Jump to content

mysqli results ... is it necessary to reset the array pointer


Recommended Posts

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.