busby Posted January 9, 2011 Share Posted January 9, 2011 here is some simple code for getting and displaying fata from a database $sql="SELECT * FROM messages WHERE m_id = '".$id."'"; $result = mysql_query($sql); <table border='0' cellspacing="4"> while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<th>Message</th>"; echo "</tr>"; echo "<tr>"; echo "<td>" . $row['message'] . "</td>"; echo "</tr>"; } now ive used that while loop to display those results how can i do that again without having a new SQL statement. i cant do 2 while loops because the first one has already got to the end of the amount of rows basically how can i have another while loop displaying those same results again? Link to comment https://forums.phpfreaks.com/topic/223888-can-i-do-2-while-loops-for-the-results-of-1-select-statement/ Share on other sites More sharing options...
BlueSkyIS Posted January 9, 2011 Share Posted January 9, 2011 you can. one way is to use mysql_data_seek to set the result pointer back to the first result: } // end first loop mysql_data_seek($result,0); while ($data = mysql_fetch_array($result)) { // start second loop Link to comment https://forums.phpfreaks.com/topic/223888-can-i-do-2-while-loops-for-the-results-of-1-select-statement/#findComment-1157096 Share on other sites More sharing options...
busby Posted January 9, 2011 Author Share Posted January 9, 2011 excellent! thankyou exactly what i was looking for and such a simple solution. Link to comment https://forums.phpfreaks.com/topic/223888-can-i-do-2-while-loops-for-the-results-of-1-select-statement/#findComment-1157106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.