Re: [PHP] finding a particular record within a MySQL result set

2007-04-10 Thread Richard Lynch
On Wed, April 4, 2007 12:07 pm, James Tu wrote:
 I've cross posted this to the MySQL list...

 Here's my original post.

 Is there some quick way to do the following in MySQL?  (I know I
 can use PHP to search through the result set, but I wanted to see
 if there's a quick way using some sort of query)

 Let's say I know that Joe is from Maine.
 I want to do a query of all employees from Maine, ordered by hiring
 date, and figure out where Joe falls in that list. (i.e. which
 record number is he?)

 -James



 Here's my new plan of attack...

 Right now I'm trying to use PHP to do a binary search on the result
 set so I don't have to traverse the entire result set.

 I'm using PHP's mysql_data_seek() to move the pointer within the
 result set and looking at the data to do the necessary comparisons.

 What do people think of this approach?


It will probably be slow if you have many records in result set.

In what way is it even meaningful to figure out where Joe falls in the
list?...

Whatever it means, and whatever that is for, it ought to be stored in
the DB in the first place, probably...

Or you're just plain breaking good practices in a Big Way that will
hurt you later.

Hard to tell...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] finding a particular record within a MySQL result set

2007-04-04 Thread James Tu

I've cross posted this to the MySQL list...

Here's my original post.

Is there some quick way to do the following in MySQL?  (I know I  
can use PHP to search through the result set, but I wanted to see  
if there's a quick way using some sort of query)


Let's say I know that Joe is from Maine.
I want to do a query of all employees from Maine, ordered by hiring  
date, and figure out where Joe falls in that list. (i.e. which  
record number is he?)


-James




Here's my new plan of attack...

Right now I'm trying to use PHP to do a binary search on the result  
set so I don't have to traverse the entire result set.


I'm using PHP's mysql_data_seek() to move the pointer within the  
result set and looking at the data to do the necessary comparisons.


What do people think of this approach?

-James

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] finding a particular record within a MySQL result set

2007-04-04 Thread Jim Moseby
 
 I've cross posted this to the MySQL list...
 
 Here's my original post.
 
  Is there some quick way to do the following in MySQL?  (I know I  
  can use PHP to search through the result set, but I wanted to see  
  if there's a quick way using some sort of query)
 
  Let's say I know that Joe is from Maine.
  I want to do a query of all employees from Maine, ordered 
 by hiring  
  date, and figure out where Joe falls in that list. (i.e. which  
  record number is he?)
 
  -James
 
 
 
 Here's my new plan of attack...
 
 Right now I'm trying to use PHP to do a binary search on the result  
 set so I don't have to traverse the entire result set.
 
 I'm using PHP's mysql_data_seek() to move the pointer within the  
 result set and looking at the data to do the necessary comparisons.
 
 What do people think of this approach?
 

You will probably get a better approach from the mysql list, but from a PHP
solution perspective, I'd load up an array with the result set and use key()
to get the number.

The example at http://php.net/key does exactly that.

JM

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] finding a particular record within a MySQL result set

2007-04-04 Thread Jim Moseby
 
 You will probably get a better approach from the mysql list, 
 but from a PHP
 solution perspective, I'd load up an array with the result 
 set and use key()
 to get the number.
 
 The example at http://php.net/key does exactly that.
 

Or array_search()  :)

JM

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] finding a particular record within a MySQL result set

2007-04-04 Thread James Tu
I've looked at those, but both approaches requires traversing through  
the entire mysql result set to create another array ( could be memory  
intensive if the result set is large...100,000 ? )


-James

On Apr 4, 2007, at 1:39 PM, Jim Moseby wrote:



You will probably get a better approach from the mysql list,
but from a PHP
solution perspective, I'd load up an array with the result
set and use key()
to get the number.

The example at http://php.net/key does exactly that.



Or array_search()  :)

JM



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] finding a particular record within a MySQL result set

2007-04-04 Thread Jim Moseby
 
 
 I've looked at those, but both approaches requires traversing 
 through  
 the entire mysql result set to create another array ( could 
 be memory  
 intensive if the result set is large...100,000 ? )
 
 -James
 

I agree.  That's why I said the mysql group will give you better answers.
Really, the best solution is to just get your answer from mysql.  I am 100%
sure you can forge an SQL query or series of queries that will return the
number you want.  

JM

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] finding a particular record within a MySQL result set

2007-04-04 Thread Martin Alterisio

2007/4/4, James Tu [EMAIL PROTECTED]:


I've cross posted this to the MySQL list...

Here's my original post.

 Is there some quick way to do the following in MySQL?  (I know I
 can use PHP to search through the result set, but I wanted to see
 if there's a quick way using some sort of query)

 Let's say I know that Joe is from Maine.
 I want to do a query of all employees from Maine, ordered by hiring
 date, and figure out where Joe falls in that list. (i.e. which
 record number is he?)

 -James



Here's my new plan of attack...

Right now I'm trying to use PHP to do a binary search on the result
set so I don't have to traverse the entire result set.

I'm using PHP's mysql_data_seek() to move the pointer within the
result set and looking at the data to do the necessary comparisons.

What do people think of this approach?

-James

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



There is a previous thread in this list regarding the same topic:

http://marc.info/?t=11668863811

This is the solution I've used for this kind of problems, and posted as a
response to that thread:

http://marc.info/?m=116697534311544