By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,034 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,034 IT Pros & Developers. It's quick & easy.

resetting the result of a mysql query

tolkienarda
100+
P: 316
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
Jan 18 '07 #1
Share this Question
Share on Google+
5 Replies


ronverdonk
Expert 2.5K+
P: 4,258
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:
Jan 18 '07 #2

tolkienarda
100+
P: 316
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
Jan 18 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
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:
Jan 18 '07 #4

tolkienarda
100+
P: 316
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
Jan 18 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.