I found a script to display output like this
1 2
3 4
5 6
Here is the code:
<?php
$columns = 2;
$count = 0;
$num_rows = mysql_num_rows($result);
echo "<table>";
echo "<tr>";
for($i=0; $i < $num_rows; $i++)
{
$row = mysql_fetch_array ($result);
if($i % $columns == 0 && $i != 0)
{
echo "</tr>";
echo "<tr>";
$count = 0;
}
echo "<td>" . $row['stuff'] . "</td>";
$count++;
}
// This makes sure all the columns are filled
// Without this, when $num_rows % $columns does not equal 0
// There would be less columns in the last <tr> then $columns
if($columns != $count)
{
for($i = 0; $i < ($columns - $count); $i++)
{
echo"<td bgcolor=red> </td>"; //Change this if you want to fill it with something else
}
}
echo "</tr>";
echo "</table>";
?>
How would one dispay the retrieved information in more than one cell for each result?
For example:
<Table>
<tr><td>result1 picture</td> <td>result2 picture</td> </tr>
<tr><td>result1 description</td><td>result2 description</td></tr>
<tr><td>result3 picture</td><td>result4 picture</td> </tr>
<tr><td>result3 description</td><td>result4 description</td></tr>
</table>
1 2
3 4
5 6
Here is the code:
<?php
$columns = 2;
$count = 0;
$num_rows = mysql_num_rows($result);
echo "<table>";
echo "<tr>";
for($i=0; $i < $num_rows; $i++)
{
$row = mysql_fetch_array ($result);
if($i % $columns == 0 && $i != 0)
{
echo "</tr>";
echo "<tr>";
$count = 0;
}
echo "<td>" . $row['stuff'] . "</td>";
$count++;
}
// This makes sure all the columns are filled
// Without this, when $num_rows % $columns does not equal 0
// There would be less columns in the last <tr> then $columns
if($columns != $count)
{
for($i = 0; $i < ($columns - $count); $i++)
{
echo"<td bgcolor=red> </td>"; //Change this if you want to fill it with something else
}
}
echo "</tr>";
echo "</table>";
?>
How would one dispay the retrieved information in more than one cell for each result?
For example:
<Table>
<tr><td>result1 picture</td> <td>result2 picture</td> </tr>
<tr><td>result1 description</td><td>result2 description</td></tr>
<tr><td>result3 picture</td><td>result4 picture</td> </tr>
<tr><td>result3 description</td><td>result4 description</td></tr>
</table>