a simple
$stuff = mysql_query(\"SELECT * FROM users\");
while($s = mysql_fetch_array($stuff)){
# ....
}
while($r = mysql_fetch_array($stuff)){
# ...
}
If you user "foreach" instead of "while" you'll not have any problem and no need to mysqli_seek_data() :
//1st loop :
foreach($stuff as $row)
{
echo $row['...'];
}
...
//2nd loop :
foreach($stuff as $row)
{
echo $row['...'];
}
Here is another simpler solution:
$slq = "SELECT * FROM users";
$stuff1 = mysql_query($slq);
while($s = mysql_fetch_array($stuff1)){
# ....
}
$stuff2 = mysql_query($slq);
while($r = mysql_fetch_array($stuff2)){
# ...
}
Assign the sql to a variable, and call mysql multiple times.
no more mysql. use mysqli or pdo
$stuff = mysql_query("SELECT * FROM users");
while($s = mysql_fetch_array($stuff)){
# ....
}
// add this line
mysql_data_seek( $stuff, 0 );
while($r = mysql_fetch_array($stuff)){
# ...
}
Should do the trick
Another way is of course to store your result in an array and reuse that
see the docs
I guess it's because
Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.
I think moving data pointer with mysql_data_seek() would do the job But i think this is not a good way, you should usually fetch data from database once and store them
$stuff = mysql_query("SELECT * FROM users"); while($s = mysql_fetch_array($stuff)){ # .... } mysql_data_seek($stuff, 0); while($r = mysql_fetch_array($stuff)){ # ... } //ref: http://www.php.net/manual/en/function.mysql-data-seek.php