Hi,
I have a table in my database that contains several fields, which I am currently displaying the names of in my PHP, however I would like to ONLY get the names of the fields which have a value of 1 (as opposed to 0) in the row below.
ID Feature1 Feature2 Feature3
123 0 1 1
456 1 0 0
In the example case above, If I was checking the record based on an ID of 123 I wish for it to only return Features 2&3 (the name of the field)
Here is the code I have right now that grabs the field names (all of them only)
//Query the database
$query="select * from Features where ID = '$id'";
$nt=mssql_query($query);
// The total number of fields in the table
$i = mssql_num_fields($nt);
// Loop through the result set
for ($j = 1; $j < $i; $j++) {
echo "column $j\n ";
$fieldname = mssql_field_name($nt, $j);
echo "fieldname: $fieldname\n <br>";
}
This currently prints out the following data:
column 1 fieldname: Feature1
column 2 fieldname: Feature2
column 3 fieldname: Feature3
column 4 fieldname: Feature4
column 5 fieldname: Feature5
Any ideas how I can do this but based on the data in the below columns? Thanks for any help.
I have a table in my database that contains several fields, which I am currently displaying the names of in my PHP, however I would like to ONLY get the names of the fields which have a value of 1 (as opposed to 0) in the row below.
ID Feature1 Feature2 Feature3
123 0 1 1
456 1 0 0
In the example case above, If I was checking the record based on an ID of 123 I wish for it to only return Features 2&3 (the name of the field)
Here is the code I have right now that grabs the field names (all of them only)
//Query the database
$query="select * from Features where ID = '$id'";
$nt=mssql_query($query);
// The total number of fields in the table
$i = mssql_num_fields($nt);
// Loop through the result set
for ($j = 1; $j < $i; $j++) {
echo "column $j\n ";
$fieldname = mssql_field_name($nt, $j);
echo "fieldname: $fieldname\n <br>";
}
This currently prints out the following data:
column 1 fieldname: Feature1
column 2 fieldname: Feature2
column 3 fieldname: Feature3
column 4 fieldname: Feature4
column 5 fieldname: Feature5
Any ideas how I can do this but based on the data in the below columns? Thanks for any help.