Forum Moderators: coopster
I expect to see the columns of that table in the webpage but I can't. Instead I get an empty page.
Can you please tell me where is the error by analyzing the code?
Thanks in advance:
<?php
// Define MySQL connection
$connection = Mysql_connect('localhost', '', '');
// select database
mysql_select_db('cookbook', $connection);
// function to extract column names
function get_column_names_with_show($connection, $tbl_name)
{
// query definition
$query = "SHOW COLUMNS FROM item ";
// execute query and keep result_id in $result
$result = mysql_query($query, $connection);
If(!$result)
{
return (FALSE);
}
// array to contain retrieved column names
$names = array();
// Loop to return an array of names
while( list($name, $type, $null, $key, $default, $extra) = mysql_fetch_row($result))
{
$names[]=$name; // append name to array
}
mysql_free_result($result);
return($names);
$names = get_colum_names_with_show($connection, 'item') ;
}
?>
[edited by: eelixduppy at 1:04 am (utc) on Feb. 23, 2008]
[edit reason] removed credentials [/edit]
while( $row = mysql_fetch_assoc($result))
{
$col = $row['field'];
$names[]=$col; // append name to array
}
mysql_free_result($result);
return($names);
to retrieve only the first column of the result in which i am interested and then append the successive values to the $names array.
As you see i also took out the line mentionned above, but still getting an empty page.
Note that I tested if the sql really is ok before i put it in the php code.
Any idea?