You are here: Re: How to display database table data in a html table. « PHP Programming Language « IT news, forums, messages
Re: How to display database table data in a html table.

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация