hello;
<?php
$query = "select * from table where (column1='this_row')";
?>
ofcourse this will select the entire row;
however some cells within the row will be 'null';
for the non-null cells I want the NAMEs of the columns;
any thoughts?
thanks
Shannon Burnett
Asheville NC USA
getting column names from mysql
Moderator: General Moderators
-
coreycollins
- Forum Commoner
- Posts: 67
- Joined: Sun Feb 01, 2004 1:04 pm
- Location: Michigan
This will get you the names of the fields (columns).
http://www.php.net/manual/en/function.m ... fields.php
http://www.php.net/manual/en/function.m ... fields.php
// get an array of the column names, however you do that, adodb here
// "show columns from table" maybe a helpful query otherwise
$columns = $conn->MetaColumnNames($table);
foreach ($colums as $col) {
$query[] = "ifnull($col, '$col')";
}
$sql = "select ".implode(',',$query)." from table where condition";
...
make sense? ifnull() returns the first argument if it's not null, else it returns the second.
// "show columns from table" maybe a helpful query otherwise
$columns = $conn->MetaColumnNames($table);
foreach ($colums as $col) {
$query[] = "ifnull($col, '$col')";
}
$sql = "select ".implode(',',$query)." from table where condition";
...
make sense? ifnull() returns the first argument if it's not null, else it returns the second.
-
fastfingertips
- Forum Contributor
- Posts: 242
- Joined: Sun Dec 28, 2003 1:40 am
- Contact:
To get the column name you have the mysql_fetch_field() that returns you an associative array or an object (i do not remember well at this time), to give you the code :
while($i<mysql_num_rows($result))
{
$colNames=mysql_fetch_field($result);
$i++;
}
Anyway to get the name of the field: $colNames->name (thuh it seems to be an object
)
while($i<mysql_num_rows($result))
{
$colNames=mysql_fetch_field($result);
$i++;
}
Anyway to get the name of the field: $colNames->name (thuh it seems to be an object