Php+mysql Implementing output Print database table structure and output table contents

Source: Internet
Author: User

1

<form id= "Form1" Name= "Form1" action= "2.php" method= "Get" >The following tables are available in this database: <input type= "text" name= "Shuru" value= ""/> <input type= "Submit" Name= "sub" value= "Query" > </form>&lt ;?PHP/** * By:qingsong * DATE:2015/4/18 0018 * time:22:17*/Header(' Content-type:text/html;charset=utf-8 ');$jieshou= "Qingsong";Define("Connect", @mysql_connect("localhost", "root", "root"));//List table names//echo "database--". $jieshou. " <br/><br/> ";    $dbs= @Mysql_list_tables("Qingsong",connect); $rows=mysql_num_rows($dbs); $i= 0;  while($i<$rows)    {        $db _name[$i] =Mysql_tablename($dbs,$i); Echo $db _name[$i]." </br> " ; $i++; }

2

<?PHP/** * By:qingsong * DATE:2015/4/21 0021 * time:21:52*/ Header(' Content-type:text/html;charset=utf-8 ');@$conn=NewMysqli ("localhost", "root", "root");if($conn->connect_error) die("Database connection failed.")$conn-connect_error);$shuru=$_get["Shuru"];functionChaxun ($shuru){    @$conn=NewMysqli ("localhost", "root", "root"); $conn->select_db ("Qingsong");$sql= "SHOW full COLUMNS from".$shuru";$result=$conn->query ($sql);if(!$result) die("Data query Failed");//$row _num= $result->num_rows;//$col _num= $result->field_count;//echo "number of rows: $row _num, number of columns: $col _num";Echo"<br/>";Echo"<table bordercolor= #4F88EF align=center border=1><tr>";//Table while($field=$result-Fetch_field ()) {    Echo"<th>$field->name</th> ";//$field The Name property :}Echo"</tr>"; while($res=$result-Fetch_row ()) {    Echo"<tr>"; foreach($res  as $val)        Echo"<th>$val</th> "; Echo"</tr>";}Echo"</table>";} Chaxun ($shuru);><input type= "button" onclick= "window.location.href= ' 4.php '" value= "View Data" >

<?PHP/** * By:qingsong * DATE:2015/4/21 0021 * time:22:39*/Header(' Content-type:text/html;charset=utf-8 ');$link=mysql_connect("localhost", "root", "root");if(!$link)Echo"The database is not connected successfully!";Else Echo"Database connection succeeded!<br/>";mysql_select_db("Qingsong",$link);//Select Database$q= "SELECT * from admin";//SQL query Statementsmysql_query("SET NAMES UTF8");$rs=mysql_query($q,$link);//Get Data Setif(!$rs){ die("Valid result!");}Echo"<table>";Echo"<tr><td>ID</td><td> Manage Accounts </td><td> gender </td><td>&nbsp; password </ Td><td> Registration date </td><td> Front vest </td></tr> "; while($row=Mysql_fetch_row($rs))Echo"<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>$row[5]</td></tr> ";//Show DataEcho"</table>";Mysql_free_result($rs);//To close a data setEcho"<br/><br/>&nbsp;&nbsp;<a href=3.php?id=qingsong> back to </a>". "<br>";

Php+mysql Implementing output Print database table structure and output table contents

Related Article

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.