niche Posted October 24, 2010 Share Posted October 24, 2010 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 More sharing options...
Fmdpa Posted October 24, 2010 Share Posted October 24, 2010 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 More sharing options...
Synook Posted October 24, 2010 Share Posted October 24, 2010 You can also use LIMIT to only request data starting at the second row.Otherwise, most appropriate would be to just use mysql_data_seek(). Link to comment Share on other sites More sharing options...
niche Posted October 24, 2010 Author Share Posted October 24, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.