Hi,
This looks like a simple problem, but I just can't seem to wrap my
head around it.
I'm trying to build a table dynamically, based on a result set from
mysql. There will be 9 results for a full page, with 3 table rows of 3
table cells. One result per cell. But all of the pages won't be full.
Here's one of many ways I've tried to do it:
<html>
<head>
<title>test</title>
</head>
<body>
<table width="100%" border="1">
<?php
include_once('d b.inc.php');
$query = "SELECT DISTINCT title FROM mytable LIMIT 9";
$result = mysql_query($qu ery);
while ($row = mysql_fetch_arr ay($result)) {
$title = $row['title'];
}
for ($i = 0; $i < 3; $i++) {
print ' <tr>' . "\n";
for ($e = 0; $e < 3; $e++) {
print ' <td align="center"> ' . "\n".
' title : ' . $title . "\n".
' </td>' . "\n";
}
print ' </tr>' . "\n";
}
?>
</table>
</body>
</html>
This prints out 3 rows of three like I hoped, but $title is the same
in all 9 cells. I also have tried it with the for loops inside the
while loop, which prints out 9 rows of 9 cells 9 times!
I know I'm probably missing something obvious, so maybe someone can
point out what I'm doing wrong?