zoukankan      html  css  js  c++  java
  • PHP获取MySQL数据库中的整张表的数据

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>获取数据表中的数据</title>
    </head>
    <body>
    <?php
        $table= 'grades';
        $database= 'sel';
        $link= @mysqli_connect('localhost','root','',$database) or die('错误:'.mysqli_connect_error());
        mysqli_set_charset($link,'utf8');
        $rs= mysqli_query($link,'select * from '.$table);   
        $list= mysqli_fetch_all($rs,MYSQLI_ASSOC);  
    ?>
        <table>
            <tr>
                <?php foreach($list as $key=>$value): ?>
                    <th><?php echo array_keys($value)[$key] ?></th>
                <?php endforeach;?>
            </tr>
            <?php foreach($list as $rows):?>
            <tr>
                <?php for($i=0; $i<count($list); $i++):?>
                    <td><?php echo $rows[array_keys($rows)[$i]]?></td>
                <?php endfor;?>
            </tr>
            <?php endforeach;?>
        </table>
    </body>
    </html>
  • 相关阅读:
    MySQL命令2
    MySQL命令1
    前端之HTML1
    linux命令之df dh
    python call java jar
    redis-py中的坑
    YARN应用程序的开发步骤
    Yarn的服务库和事件库使用方法
    SSH无密码验证
    在centos 6.5 在virtual box 上 安装增强版工具
  • 原文地址:https://www.cnblogs.com/SharkJiao/p/14087606.html
Copyright © 2011-2022 走看看