How to use PHP & MySQL Get Field Name Learn PHP how to using PHP get field name from a mysql database table.
ShotDev Focus:
- PHP & MySQL get field name from table.
Example
php_list_table.php
<html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <? $objConnect = mysql_connect("localhost","root","root") or die(mysql_error()); $objDB = mysql_select_db("mydatabase"); $strSQL = "SELECT * FROM customer"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); $intNumField = mysql_num_fields($objQuery); $i = 0; echo "<b>Table customer have $intNumField Fields.</b><br>"; for($i=1;$i<$intNumField;$i++) { echo $i."=".mysql_field_name($objQuery,$i)." (".mysql_field_type($objQuery,$i).")<br>"; } mysql_close($objConnect); ?> </body> </html>
Create a php file and save to path root-path/myphp/
Run
http://localhost/myphp/php_list_table.php
Screenshot