how to display column name and the values in the fields

A

Anonymous

Guest
I wish to show the content of the mysql database,

The column names are random, so i can not call the info like normal.

I wish to get all the info maybe in an array and then display it. it contains data related to my counters.

How could i do this please.

thanks
 
Hello Jason,

You mean to say that structure of table is not fixed. In another words fields keep on changing.

Can you show me the table structure?
 
this is just a snippet of the DB, as there are 100's of them
the TD is the time and date the entry was created, i format the date and time myself.

CREATE TABLE `weeklystats` (
`TD` text NOT NULL,
`videohomepage` text NOT NULL,
`The Pension Service` text NOT NULL,
`easterevent2006` text NOT NULL,
`photos from alan` text NOT NULL,
`photos from daniel` text NOT NULL,
`photos from mick` text NOT NULL,
`mayors mural visit` text NOT NULL,
`allotmentcommitteepage` text NOT NULL,
`PCT Stop Smoking homepage` text NOT NULL,
`Residents Views - Parks Police Axe` text NOT NULL,
`Library - WI FI poster` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 
Are you using Space name in the name of field?

This is wrong database practice

Either use Camle Notation or Underscore notation.
 
yes i am using spaces in the column names.

how do i read and them print the column names?
 
You wants to print the name of column or data of table?
 
Code:
<?

$link = mysql_connect("localhost", "user_name", "password");

$db_name = "database_name";

$db_link = mysql_select_db($db_name, $link);

$field_list = GetFieldList($db_name, $tbl_name);

print_r($field_list);

function GetFieldList($DB, $Table)
{
        $fldlist = mysql_list_fields($DB, $Table);
        $columns = mysql_num_fields($fldlist);

	for ($i = 0; $i < $columns; $i++)
        {
	       $Listing[] = mysql_field_name($fldlist, $i);
	}
return $Listing;
}

?>

Please dont forget to visit:
http://mukeshvariya.blogspot.com
 
Back
Top