Hi,
The code displays the results with table row2 alternating every time after table row1. For example:
table row1: A | B | C
table row2: 1 | 2 | 3
table row1: D | E | F
table row2: 4 | 5 | 6
table row1: G | H | I
table row2: 7 | 8 | 9
I want to display all of the results in table row1 first then display all the results in table row 2. For example:
table row1: A | B | C
table row1: D | E | F
table row1: G | H | I
table row2: 1 | 2 | 3
table row2: 4 | 5 | 6
table row2: 7 | 8 | 9
Hope this makes sense.
I was told to create an array in my fetch loop, then build another couple of loops to create the html markup for it to work.
Here is my new code below, but I get the following error on both of the "foreach" lines:
"Warning: Invalid argument supplied for foreach()"
What am I doing wrong?
echo "<table cellpadding=\'2\' cellspacing=\'0\'>";
echo "<tr>";
echo "<td class=\"th\" >COL1</td>";
echo "<td class=\"th\" >COL2</td>";
echo "<td class=\"th\" >COL3</td>";
echo "</tr>";
if($result && mysql_num_rows($result) > 0)
{ for ($i = 0; $i < mysql_num_rows; $i++) {
$resultArray[$i] = mysql_fetch_array($result);
}
foreach ($resultArray as $val) {
echo ('<tr>');//first row
echo ('<td>'.$val[1].'</td>');
echo ('<td>'.$val[2].'</td>');
echo ('<td>'.$val[3].'</td>');
echo ('</tr>');
}
foreach ($resultArray as $val) {
echo ('<tr>');//second row
echo ('<td>'.$val[4].'</td>');
echo ('<td>'.$val[5].'</td>');
echo ('<td>'.$val[6].'</td>');
echo ('</tr>');
}
}
echo ('</table>');