I have the following code: (query added)
$weight_table = mysql_query ("SELECT * FROM ".$prefix."weight ORDER BY wlimit DESC");
foreach ($weight as $area => $weight) {
echo $weight;
while ($weight_row = mysql_fetch_array($weight_table)) {
print_r($weight_row);
$limit = $weight_row['wlimit'];
if ($weight < $limit) {
$weight_level[$count] = $weight_row;
}
}
}
print_r($weight_level);
Where $weight_table is a mysql query result and $weight is an array.
My problem is that $weight_table seems to be expiring after the first while loop, so that the $weight array is effectively treated as having one item. This is a problem!
Can anyone suggest why php would forget a mysql result after the first use?
The first iteration through the for loop, you’re fetching all of the records from the mysql result set. Your inner while loop will run until all the rows are gone. How many rows do you want it to pull?
Also you’re re-using $weight which is a bad idea and may be causing side effects.