HOw do i determine if a field exists or not in my php/mysql application

Ok client wanted to removed three fields from thieir application.  I simply commented out the three fields in my code.  Client then realized, for old requests, they still wanted to see the data.  So I want to add code like attached, but i want to say if you are in display mode and the field Q_9 existist in the db for this record, show the attached info.

to test my theory i added q_9 back and removed data from it and it works, but the key here is Q_9 will no longer be used in the db, so how do i say if field/field name exists, ,show the data.
<?
    if ($mode=="display" && $Q['Q_9'] ==""):
    //if ($mode=="display" && !empty($Q['Q_9'])):
?>
<tr>
<td width="210" class="required"><label><?=$Q['Q_9']?></label></td>
<td width="460"><?=printRadio($mode,'Q_9',getSelectValues('Q_9'),$A['Q_9'])?></td>
</tr>
<?endif;?>
<tr>

Open in new window

LVL 1
justmelatAsked:
Who is Participating?
 
Aleksandar BradarićConnect With a Mentor Software DeveloperCommented:
Try something like this (TABLE_SCHEMA is actually your DB name):
mysql> SELECT COLUMN_NAME FROM COLUMNS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'myTable';
+-------------+
| COLUMN_NAME |
+-------------+
| field       | 
| field2      | 
| field3      | 
+-------------+
3 rows in set (0.00 sec)

Open in new window

0
 
aamodtCommented:
this code provided will show the data when the field Q_9 exist
<?php 
 
$result = mysql_query("SELECT * from table where field = 'Q_9');
 
if(mysql_num_fields($result) == 1) {
show data
}
 
 
?>

Open in new window

0
 
Aleksandar BradarićSoftware DeveloperCommented:
Sorry, forgot the DB name in the FROM clause:
mysql> SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME='myTable';
+-------------+
| COLUMN_NAME |
+-------------+
| field       | 
| field2      | 
| field3      | 
+-------------+
3 rows in set (0.00 sec)

Open in new window

0
 
Aleksandar BradarićSoftware DeveloperCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.