Page 1 of 1

HELP! Nested while and for loop

Posted: Mon Mar 07, 2011 11:17 pm
by cecille1127
hello everyone, i'm new here
i badly need your help with this code: :banghead: :banghead: :banghead:

$qdev=mysql_query("select distinct(device) from wipdataperarea where creation_date like '$today%' and gtc='AL' order by gtc,device");
$device=mysql_num_rows($qdev);

$i=0;
while ($dev=mysql_fetch_assoc($qdev)) {
echo "<tr>";
echo "<td>" . $dev['device']. "</td>";

$qarea=mysql_query("select distinct(area2) from wipdataperarea where creation_date like '$today%' and gtc='AL'");
$result=mysql_num_rows($qarea);

for ($i="0"; $i<($area=mysql_fetch_assoc($qarea)); $i++) {
$query=mysql_query("select distinct(wip_pro), description from wipdataperarea where creation_date like '$today%' and area2 = '" . $area['area2'] . "' and
gtc='AL'");
$count=mysql_num_rows($query);
$x=0;

for ($x="0"; $x<($row=mysql_fetch_assoc($query)); $x++) {
$sql=mysql_query("select count from wipdataperarea where creation_date like '$today%' and device = '" . $dev['device'] . "' and area2 = '" .
$area['area2'] . "' and wip_pro = '" . $row['wip_pro'] . "' and description = '" . $row['description'] . "' and gtc='AL'");
$cnt=mysql_num_rows($sql);

for ($y="0"; $y<($count=mysql_fetch_assoc($sql)); $y++) {
echo "<td>" . $count['count']. "</td>";
}
}
}
echo "</tr>";

}
echo "</tr>";

I encounter "Internal server error at the last for loop where i need to output the $count['count']

Re: HELP! Nested while and for loop

Posted: Tue Mar 08, 2011 10:30 am
by social_experiment
The Manual wrote: Description
array mysql_fetch_assoc ( resource $result )
Returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead. mysql_fetch_assoc() is equivalent to calling mysql_fetch_array() with MYSQL_ASSOC for the optional second parameter. It only returns an associative array.

Code: Select all

($i="0"; $i<($area=mysql_fetch_assoc($qarea)); $i++) 
You are trying to test $i against an array. You don't need quotation marks around $i = 0 and the second expression in a for loop is a comparison so you shoud use something like mysql_num_rows() to get a value to test against.