Connecting Tech Pros Worldwide Help | Site Map

resetting the result of a mysql query

tolkienarda's Avatar
Needs Regular Fix
 
Join Date: Dec 2006
Posts: 316
#1: Jan 18 '07
Hi all
how would i go about reseting the internal pointer in a mysql_query result

I use a loop to display the results of a colom in a select box
here is the loop
Expand|Select|Wrap|Line Numbers
  1.         $i=1;
  2.             while ($i<=$row)
  3.             {
  4.                 $row2=mysql_fetch_row($result);
  5.                 echo '<option value="', $row2[1], '">', $row2[2], '</option>';//outputs the unique login name
  6.                 $i++;
  7.             }
  8.  
now i resuse this code with different variables here it is
Expand|Select|Wrap|Line Numbers
  1.         $k=1;
  2.         reset($result);
  3.             while ($k<=$row)
  4.             {
  5.                 $msrow=mysql_fetch_row($result);
  6.                 echo '<option value="', $msrow[1], '">', $msrow[2], '</option>';//outputs the unique login name
  7.                 $k++;
  8.             }
  9.  
as you can see i've used the reset() function but it dosen't seem to work

thanks for any help

eric
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Jan 18 '07

re: resetting the result of a mysql query


You have to use the mysql_data_seek() command (reset() is for arrays).
[php]$reset = mysql_data_seek($result, 0);
if (!$reset)
echo 'MySql data seek Error' . mysql_error();
$k = 1;
while ($k<=$row)
{
... etc ...[/php]Ronald :cool:
tolkienarda's Avatar
Needs Regular Fix
 
Join Date: Dec 2006
Posts: 316
#3: Jan 18 '07

re: resetting the result of a mysql query


thanks

and on a side note where can i get the source of functions like reset() and other prebuilt functions. as i learn more about php i would like to start learning the details

thanks again
eric
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#4: Jan 18 '07

re: resetting the result of a mysql query


You better do some PHP tutorials on the web. All the php functions can be found in the standard PHP documentation at www.php.net. Good luck.

Ronald :cool:
tolkienarda's Avatar
Needs Regular Fix
 
Join Date: Dec 2006
Posts: 316
#5: Jan 18 '07

re: resetting the result of a mysql query


I've done several of the tutorals like on w3cschools and here as well as several others and even a lynda.com training video but if there are more you can sugges that would be great
Reply