PHP+MYSQL實現輸出列印資料庫表結構和輸出表內容

來源:互聯網
上載者:User

標籤:

1

<form id="form1" name="form1" action="2.php" method="get">    本資料庫中有以下表:<input type="text" name="shuru" value=""/>    <input type="submit" name="sub" value="查詢">    </form><?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"));//列出表名//echo "資料庫--".$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=new mysqli("localhost","root","root");if($conn->connect_error) die("資料庫連接失敗".$conn->connect_error);$shuru=$_GET["shuru"];function chaxun($shuru){    @$conn=new mysqli("localhost","root","root");    $conn->select_db("qingsong");$sql="SHOW FULL COLUMNS FROM "."$shuru";$result=$conn->query($sql);if(!$result) die("資料查詢失敗");//$row_num=$result->num_rows;//$col_num=$result->field_count;//echo" 行數為:$row_num,列數為:$col_num ";echo "<br/>";echo "<table bordercolor=#4F88EF align=center border=1><tr>";//表格while ($field=$result->fetch_field()){    echo "<th>$field->name</th>";//$field的name屬性..}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="查看資料">

<?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 "資料庫沒有串連成功!";else echo "資料庫連接成功!<br/>";mysql_select_db("qingsong", $link);          //選擇資料庫$q = "SELECT * FROM admin";                   //SQL查詢語句mysql_query("SET NAMES utf8");$rs = mysql_query($q, $link);                     //擷取資料集if(!$rs){die("Valid result!");}echo "<table>";echo "<tr><td>ID</td><td>管理帳號</td><td>性別</td><td>&nbsp;密碼</td><td>註冊日期</td><td>前台馬甲</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>";   //顯示資料echo "</table>";mysql_free_result($rs);                    //關閉資料集echo "<br/><br/>&nbsp;&nbsp;<a href=3.php?id=qingsong>返回</a>"." <br>";

 

PHP+MYSQL實現輸出列印資料庫表結構和輸出表內容

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.