Jump to content

advancing throug a mysql resource


niche

Recommended Posts

I just created a mysql resource called $result that's been ordered.I need to advance past the first row to get a value from the second row.I thought calling mysql_fetch_array twice would advance me through $result to the second row.Is this correct? If so, I'll have to keep looking for my mistake. If not, how do I advance to the second row in $result?

Link to comment
Share on other sites

Is there a reason that you can't use a WHERE clause to select the row you want?If not, then I suppose you could use an if statement to check which row you are at.

<?php$con = mysql_connect("localhost","peter","abc123");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("my_db", $con);$result = mysql_query("SELECT * FROM Persons");$num = mysql_fetch_array($result);for ($i = 0; $i < $num; $i++) {if ($i == 1) echo 'Second row selected!';}mysql_close($con);?>

I didn't test the code above, so it may not work. Maybe there's a better way to do it...?

Link to comment
Share on other sites

Fmdpa and Synook, thanks for your help. I'm always a encouraged by how many different ways there are to do the same thing.Niche

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...