php--dynamically generate SQL query tables

Source: Internet
Author: User

<?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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.