Forum Moderators: open

Message Too Old, No Replies

Automatically display all data in a table?

MySQL / PHP

         

TheVanWarehouse

2:12 pm on May 27, 2009 (gmt 0)

10+ Year Member



Is there a way to automatically display all field names and data in a table (MySQL using PHP) - without having to specify field names etc?

I remember doing this in Access and found it useful when examining a new database.

Demaestro

2:32 pm on May 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



select * from table_name

brotherhood of LAN

3:17 pm on May 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Elaborating a little...

$query = mysql_query('SELECT * FROM table_name'); 
$start = FALSE;

echo '<table border="1">';
while($row = mysql_fetch_array($query,MYSQL_ASSOC))
{
if(!$start)
{
$start = TRUE;
echo '<tr>';
foreach($row as $key => $value)
echo '<th>'.$key.'</th>';
echo '</tr>';
}
echo '<tr><td>'.implode('</td><td>',$row).'</td></tr>';
}
echo '</table>';

Demaestro

4:11 pm on May 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thanks brother,

I mis-read it, thought it said ".... from a table"

[edited by: Demaestro at 4:12 pm (utc) on May 27, 2009]