dongyue8640 2011-11-02 10:02
浏览 33
已采纳

回声表从phpMyAdmin到html表

How would you echo out a MySQL table into a html table. Like phpMyAdmin shows a table, just a basic table structure with the name of the fields and all the records in that table.

Any help would be appreciated

  • 写回答

4条回答 默认 最新

  • drflkphi675447 2011-11-02 10:09
    关注

    This code show the a dinamic table with all the field and all the rows returned from a query...

    This works for all pourpose you need

    • list all tables
    • show table field description
    • show all table rows

      <?php
       // list all the table in database
       $result = mysql_query("show tables");
       // show all the field with type, lenght,description of a specific table
       $result = mysql_query("DESCRIBE table_name");
       // show a specific tables row 
       $result = mysql_query("SELECT * FROM table_name");
       if (mysql_num_rows($result)>0){
       $r = mysql_fetch_array($result,MYSQL_ASSOC);
       $table="<table><tr>";
       $firstLine="<tr>";
       foreach ($r as $k => $v){
         $table .="<td>".$k."</td>";
         $firstLine .="<td>".$v."</td>";
       }
       $table.="</tr>".$firstLine."</tr>";
       while($r = mysql_fetch_array($result,MYSQL_ASSOC)){
         $table.="<tr>";
         foreach($r as $k => $v)
           $table.="<td>".$v."</td>";
         $table.="</tr>";
       }
        $table .="</table>";
       echo $table;
      }
      ?>
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度