Tags
PHP , MySQL
Asked 8 years ago
27 Sep 2016
Views 1683
sachin

sachin posted

how to get mysql table field list in php ?

i am making csv export functionality form table

so when some choose table i want to show them field list with checkbox so they can checked which they want to export
mysql_list_fields is the function . i googled for it and get answer - debugger  
Sep 28 '16 05:27
jagdish

jagdish
answered Nov 30 '-1 00:00

mysql function is there for it mysql_list_fields but it deprecated in PHP 5.4.0

so you should use


$result_set=mysqli_query("SHOW COLUMNS FROM `tablename_here`")
while($field_list=mysqli_fetch_assoc($result)){
$fields[]=$field_list;
}
print_r($fields);

in above code it find columns from given table , per row show you each field so , while loop give you all list at end
and i used mysqli for now because mysql extension will be removed soon so .
or you can use PDO for better use

Thanks hope it help

Post Answer