I have always been getting the results of a database but never the column name, now I have a situation where i need both the column name and result together.
I have a simple code that shows the column name and adjacent to it show results where the results are = 1.
So let's say my table is looking like this
| Science | Maths | Biology | English |
---------------------------------------------------------
| 1 | 0 | 0 | 1 |
So basically what I am looking for is something like
Table Name | Results
---------------------------------
Science | 1
English | 1
I search around the web and found the usage of INFORMATION_SCHEMA.COLUMNS but that doesn't seem to work in the way I wanted it to. I somehow need to include both INFORMATION_SCHEMA.COLUMNS as well as select * WHERE user = $user kinda stuff.
My approach.
$i = 0;
$result = mysql_query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'trophy' WHERE UPPER(username) = UPPER('$searchuser')");
while($row = mysql_fetch_array($result))
{
echo $row['COLUMN_NAME'];
echo '-'
echo $row[$i];
$i++;
}