The looping of the $row is not correct

riymcswkok

New Member
I want to create a table as below :\[code\]+-------+--------+--------+----------+| | Fact | Pass | Fail |+-------+--------+--------+----------+| 1 | FEP | 1 | 0 |+-------+--------+--------+----------+| 2 | FK | 1 | 0 |+-------+--------+--------+----------+| 3 | FSKPM | 0 | 1 |+-------+--------+--------+----------+\[/code\]Here is my code (mixed of PHP and HTML) : The query part :\[code\]$query = "SELECT *,COUNT(Status) FROM request GROUP BY Status, Fact";$result = mysql_query($query) or die(mysql_error());$Index = 1;$Fact = array("FEP", "FK", "FSKPM");\[/code\]And the table showing part :\[code\]<?php for($i=0;$i<sizeof($Fact);$i++) { $row = mysql_fetch_assoc($result);?> <tr> <td><?php echo $Index; ?></td> <td><?php echo $Fact[$i]; ?></td> <td> <?php if($row['Fact'] == $Fact[$i] && $row['Status'] == "Pass") echo $row['COUNT(Status)']; else echo "0"; ?> </td> <td> <?php if($row['Fact'] == $Fact[$i] && $row['Status'] == "Fail") echo $row['COUNT(Status)']; else echo "0"; ?> </td> </tr><?php $Index++; } ?>\[/code\]But what I get from my code is :\[code\]+-------+--------+--------+----------+| | Fact | Pass | Fail |+-------+--------+--------+----------+| 1 | FEP | 1 | 0 |+-------+--------+--------+----------+| 2 | FK | 0 | 0 |+-------+--------+--------+----------+| 3 | FSKPM | 0 | 0 |+-------+--------+--------+----------+\[/code\]What I know so far about the error I made is the \[code\]$row['Fact']\[/code\] is keeps equal to \[code\]FEP\[/code\], that's why the others column are all '0'.How can I solve this problem?
 
Back
Top