Select and Print table names and everything in a cell

Hi All

I am having troubles getting my head around this…

I need to select and print all the columns and cells in a table. The result should look something like this:

id: 1
ref: 1234
name: Some Person
telephone: 1234 5678

With the above the first bit is the column name and the second is the information from the row.

I hope this makes sense and would greatly appreciated any help.

Many Thanks


I’m assuming table means database table. This should work for a MySQL table:

$sql = "select * from my_table";
$result = mysql_query($sql);
$num_fields = mysql_num_fields($result);
while ( $record = mysql_fetch_assoc($result) ) {
	for ( $i=0; $i< $num_fields; $i++ ) {
		$fieldname = mysql_field_name($result, $i);
		print $fieldname . ': ' . $record[$fieldname] . '<br>' . "\
	print '<br>' . "\

Is that close to what you’re looking for?

AWESOME - you are a ledged - Thanks

Just be sure to escape the output, as is standard practice, to help prevent the danger of cross-site scripting.

print $fieldname . ': ’ . htmlentities($record[$fieldname]) . ‘<br>’ . "