This programme shows all the fields in a table of a database in MySQL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | /******************************************************* * MYCPLUS Sample Code - https://www.mycplus.com * * * * This code is made available as a service to our * * visitors and is provided strictly for the * * purpose of illustration. * * * * Please direct all inquiries to saqib at mycplus.com * *******************************************************/ <html> <head> <title>mysql_list_fields</title> </head> <body> <? //connect to server $dbLink = mysql_pconnect("localhost", "freetrade", ""); //get list of fields $dbResult = mysql_list_fields("freetrade", "invoice", $dbLink); //start HTML table print("<table>\n"); print("<tr>\n"); print("<th>Name</th>\n"); print("<th>Type</th>\n"); print("<th>Length</th>\n"); print("<th>Flags</th>\n"); print("</tr>\n"); //loop over each field for($i = 0; $i < mysql_num_fields($dbResult); $i++) { print("<tr>\n"); print("<td>" . mysql_field_name($dbResult, $i) . "</td>\n"); print("<td>" . mysql_field_type($dbResult, $i) . "</td>\n"); print("<td>" . mysql_field_len($dbResult, $i) . "</td>\n"); print("<td>" . mysql_field_flags($dbResult, $i) . "</td>\n"); print("</tr>\n"); } //close HTML table print("</table>\n"); ?> </body> </html> |