View Single Post
Old 08-27-2009, 01:43 PM   #6 (permalink)
Dave
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default

Wildhoney --

Thanks very much. That was very helpful. In all my Googling, I did not come across a mention of "mysql_data_seek." Wonder why?

Anyway, I read more about the mysql_data_seek function on php.net, and the user posts were very interesting.

Here is Kenneth Nash's interesting UDF from that discussion:

Code:
/*here is a nice function for converting 
a mysql result row set into a 2d array, 
a time saver if need small data from 
several rows, saves you from having to 
do Alot of queries... would be nice to 
have this built into PHP future versions :) */

// simple example query

$r = mysql_query("select user,id,ip from accounts limit 10");

// starts the for loop, using mysql_num_rows() to count
// total amount of rows returned by $r

for($i=0; 
    $i<mysql_num_rows($r); 
    $i++)
{
  // advances the row in the mysql resource $r
  mysql_data_seek($r,$i);
  
  // assigns the array keys, $users[row][field]
  $users[$i]=mysql_fetch_row($r);
}

// simple, hope someone can use it :)
// -Kenneth Nash
Dave is offline  
Reply With Quote