|
Posted by Rik on 01/26/07 18:24
McGowan <Boomer84@gmail.com> wrote:
> Hi, I'm trying to display data from a mysql database in a HTML table
> but for some reason my code isn't working. At the moment I have got it=
> to read and display the headers and the first row of the table and it
> actually creates the remaining rows in the html table but it doesn't
> put any data in them. This is my code so far:
mysql_connect(); etc...
$result =3D mysql_query($query);
if($result){
print '<table>';
$row =3D mysql_fetch_assoc($result);
$heads =3D array_keys($row);
$columns =3D count($heads);
printf('<tr>'.str_repeat('<th>%s</th>',$columns).'</tr>',$heads);
printf('<tr>'.str_repeat('<td>%s</td>',$columns).'</tr>',$row);
while($row =3D mysql_fetch_assoc($result)){
printf('<tr>'.str_repeat('<td>%s</td>',$columns).'</tr>',$row);
}
print '</table>';
}
Optionally the printf()'s could be replaced by a nice =
implode('</td><td>',$row);
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|