I have a script that gets a MySQL result consisting of an ID field (1-25) and a colour.
I then put those into a html table. I am trying to get a situation whereby ID's 1-5 are a row (<tr>), then I start a new row (</tr><tr>) at ID 6. (and going forward also row 11,16,21). But at present it doesn't work. It seems to be assigning 6 as every ID, and so it is creating a new row at each stage.
Code: Select all
$result = mysql_query("SELECT `id`, `colour` FROM `db1`.`squares` ORDER BY `id` ASC");
echo '<table>';
echo '<tr>';
while($row = mysql_fetch_array($result)) {
if($row['id'] = 6) {
echo '</tr><tr>';
}
echo '<td bgcolor=' . $row['colour'] . '>'.$row['id'].'</td>';
}
</tr>
</table>
Any ideas as to why it is returning 6 for every result, and not the ID as per the MySQL statement?