<?php
Include (".. /.. /.. /applications/mamp/htdocs/dbconfig.php ");
$link = mysql_connect (
$dbconfig [' Host '],
$dbconfig [' username '],
$dbconfig [' Userpass ']
);
if (! $link) {
Die ("Connection database failed! The error number is: ". Mysql_errno ()." Failure reason ". Mysql_error ());
}
$db =mysql_select_db ($dbconfig [' dbname ']);
if (! $db) {
Die ("Select Database failed! The error number is: ". Mysql_errno ()." Failure reason ". Mysql_error ());
}
$sql = "SELECT * from Womei";
$re =mysql_query ($sql);
Output table Header
Echo ("<table width= ' 80% ' border=1 align= ' center ' cellpadding=5 cellspacing=0>");
Echo ("<tr><td>std</td><td> other 1</td><td>nanaha</td></tr>");
if (mysql_num_rows ($re) >0) {
while ($rows =mysql_fetch_assoc ($re)) {
Echo ("<tr>");
Echo ("<td>". $rows ["Std"]. " </td> ");
Echo ("</tr>");
}
}else{
Echo (' <tr><td colspan=5><font color= ' red ' > table does not have any data </tr> ');
}
Echo ("</table>");
/* CREATE TABLE
$sql = "CREATE TABLE womei (std int (3) NOT null primary key)";
if (mysql_query ($sql)) {
Echo ("CREATE table succeeded");
}
else{
Echo ("CREATE table not successful");
}
*/
/*
$sql = "INSERT into Womei (STD) VALUES (0)";
if (mysql_query ($sql)) {
Echo ("Insert data Success");
}
else{
Echo ("Insert data not successful");
}
*/
?>
This article is from the "Iamlan" blog, make sure to keep this source http://zhiliangzeng.blog.51cto.com/9324452/1546780
php--dynamically generate SQL query tables