How do you restart a while mysql_fetch_array loop?
PHP Code:while($row=mysql_fetch_array($result)){
echo $row['id']."<br>"; // will echo all the IDs
}
while($row=mysql_fetch_array($result)){ // won't run at all
echo $row['id']."<br>";
}
| SitePoint Sponsor |


How do you restart a while mysql_fetch_array loop?
PHP Code:while($row=mysql_fetch_array($result)){
echo $row['id']."<br>"; // will echo all the IDs
}
while($row=mysql_fetch_array($result)){ // won't run at all
echo $row['id']."<br>";
}
You could do the query again?
PHP Code:while($row=mysql_fetch_array($result)){
echo $row['id']."<br>"; // will echo all the IDs
}
$result = mysql_query($query);
while($row=mysql_fetch_array($result)){ // won't run at all
echo $row['id']."<br>";
}


yeah that's the simplest way, but it wouldn't it be more efficient to restart the loop than call the mysql server?
How about this: ? I've never tried it ...
http://ca.php.net/manual/en/function...-data-seek.phpPHP Code:mysql_data_seek($result, 0);
Red


You could alsways put the results from the query into a non mysql array format
Then you can use that array in any format you likePHP Code:$new_array = array();
while($row=mysql_fetch_array($result)){
$new_array[] = $row['id'];
}
PHP Code:foreach($new_array as $data) {
//etc
}
Mike Swiffin - Community Team Leader
Only a woman can read between the lines of a one word answer.....
I started out with nothing... and still got most of it left!


Bookmarks