enrmpaga Posted April 6, 2008 Share Posted April 6, 2008 In ASP i'd do something like: do while rsResults.EOF looped content... rsResults.NextResult Loop What is the equivalent in php? I could do a forloop and pre-define the number of results to bring out but i want something more dynamic. Quote Link to comment https://forums.phpfreaks.com/topic/99849-looping-through-recordsphp-mysql/ Share on other sites More sharing options...
trq Posted April 6, 2008 Share Posted April 6, 2008 while ($row = mysql_fetch_assoc($result)) { // display data } Quote Link to comment https://forums.phpfreaks.com/topic/99849-looping-through-recordsphp-mysql/#findComment-510672 Share on other sites More sharing options...
trq Posted April 6, 2008 Share Posted April 6, 2008 ps: your vbscript is invalid also. while not rsResults.EOF looped content... rsResults.Next Loop Quote Link to comment https://forums.phpfreaks.com/topic/99849-looping-through-recordsphp-mysql/#findComment-510673 Share on other sites More sharing options...
enrmpaga Posted April 6, 2008 Author Share Posted April 6, 2008 humm its not going to the next result... Quote Link to comment https://forums.phpfreaks.com/topic/99849-looping-through-recordsphp-mysql/#findComment-510737 Share on other sites More sharing options...
enrmpaga Posted April 6, 2008 Author Share Posted April 6, 2008 ah got it just used a do while loop with a counter to pull the next results out... Quote Link to comment https://forums.phpfreaks.com/topic/99849-looping-through-recordsphp-mysql/#findComment-510756 Share on other sites More sharing options...
wildteen88 Posted April 6, 2008 Share Posted April 6, 2008 Thorpe's code should work fine? Sounds like you're using the mysql_result function. Quote Link to comment https://forums.phpfreaks.com/topic/99849-looping-through-recordsphp-mysql/#findComment-510763 Share on other sites More sharing options...
enrmpaga Posted April 6, 2008 Author Share Posted April 6, 2008 correct... Quote Link to comment https://forums.phpfreaks.com/topic/99849-looping-through-recordsphp-mysql/#findComment-510772 Share on other sites More sharing options...
wildteen88 Posted April 6, 2008 Share Posted April 6, 2008 Using mysql_result is a very long winded way of getting results (IMO). By using Thorpe's code you can do away with mysql_result and just use the $row array to access your results. $query = 'SELECT * FROM table'; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { // display contents of the $row array echo '<pre>' . print_r($row, true) . '</pre>'; } To access a field from the row you'd use $row['field_name_here'] allows for much cleaner code. Quote Link to comment https://forums.phpfreaks.com/topic/99849-looping-through-recordsphp-mysql/#findComment-510780 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.