i have this code which i am trying to use in order to diplay table column names as checkbox values, i mean something liek this:
$section = mysql_query("SELECT * FROM forma");
while ($row = mysql_fetch_assoc($section)){
echo "<input type='checkbox' name='data[]' value='" . $firstrow[''] . "' />";
}
I have it in the wrong way, but how should i do in order to print column names as checkboxes, in an automatic way, not manually.
How to reach it using PDO?
$q = $dbh->prepare(“DESCRIBE forma”);
$q->execute(); $table_fields
= $q->fetchAll(PDO::FETCH_COLUMN);
Thanks
Foreword: The MySQL extension is marked as deprecated, better use mysqli or PDO
Though there are functions like mysql_field_name or SHOW COLUMNS I’d suggest using the INFORMATION_SCHEMA as it gives you more flexibility.
same thing using PDO