Jump to content

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


jtlodi

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.