You could do the query again?
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>";
}