jtlodi Posted January 13, 2010 Share Posted January 13, 2010 Hello, I've connected to mySql and can display the results of a query just beautifully. I now want to display the same results a little differently. Do I need to re-query the table to load up the array again, or can I reuse the existing array? In the code below, you can see the area that doesn't work. I don't understand this very well. (probably an understatement!) if ($result = $mysqli->query($sql)) { // If there are some results if ($result->num_rows > 0) { // Let’s show some info echo "There were ".$result->num_rows . " rows returned.<br />"; echo "We selected ".$result->field_count." fields in our query.<br />"; echo "Our thread ID is ".$mysqli->thread_id . "<br />"; // Ok, let’s show the data while ($row = $result->fetch_object()) { // Print out the contents of each row into a table echo "<tr><td>".$row->id. "</td>"; echo "<td>".$row->username."</td>"; echo "<td>".$row->password."</td>"; echo "<td>".$row->date_created."</td>"; echo "<td>".$row->access_level."</td>"; echo "<td>".$row->email."</td></tr>"; } echo "</table><hr>"; //=============== The following 'while' statement will not display anything === ??? ========== //=== do I need to reset the array pointer? ... if so, how? ================================= while ($row = $result->fetch_object()) { echo $row->username." --- " .$row->password."<br />"; } //============================================================================================ } Thank you for your help. jtlodi Quote Link to comment https://forums.phpfreaks.com/topic/188286-mysqli-results-is-it-necessary-to-reset-the-array-pointer/ Share on other sites More sharing options...
MadTechie Posted January 13, 2010 Share Posted January 13, 2010 As your using MySQLi, You could just adjusts the result pointer to row 0 of $result (mysqli-result.data-seek) e.g. $result->data_seek(0); also check mysqli.store-result Quote Link to comment https://forums.phpfreaks.com/topic/188286-mysqli-results-is-it-necessary-to-reset-the-array-pointer/#findComment-994015 Share on other sites More sharing options...
MadTechie Posted January 13, 2010 Share Posted January 13, 2010 Your welcome Quote Link to comment https://forums.phpfreaks.com/topic/188286-mysqli-results-is-it-necessary-to-reset-the-array-pointer/#findComment-994027 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.