GO TO THE BOTTOM OF THIS QUESTION FOR THE ANSWER
I'm currently working on producing a table output which basically will list users row by row. The columns on the table output will be populated by one specific SQL column, but from multiple rows (say John Smith has 4 rows, but column X has a different value on each row in this table).
To give you more context this is a textual representation of the current table state.
Name | Col1 | Col2 | Col3
---------------------------------
Name1 | 0 | X | 1
Name2 | 3 | 2 | <--- Value missing
Name3 | 2 | 1 | <--- Value missing (and this continues through the table..
As you can see on that table, the first row populates fine - but the rest of the rows afterwards seem to be ignoring an iteration of the data (hence why the rest of the rows only fill 2 columns.
The relevant code for the loop is as follows:
while ($row = mysql_fetch_assoc($result)) {
echo "<tr><td>". $row['forename'] . "</td>
<td>". $row['status'] ."</td>";
while ($col = mysql_fetch_assoc($result)) {
if ($col['id'] == $row['id']) {
echo "<td>" . $col['status'] . "</td>";
}
else if ($col['id'] != $row['id']){
echo "</tr>";
break;
}
}
}
Does anyone have any ideas about why this might be happening? I hope I've provided enough information, but if not please let me know! :)
$result
in both instances ofmysql_fetch_assoc()
. Should you not be looping on different result sets? – Martin Bean May 31 '12 at 13:43