小白工程师 html+php+mysql 实例

//index.php (绝对不能是.html格式,如果用ajax获取数据可以用html

<?php
    require_once 'functions.php';
    
    ?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <table width="50%" style="text-align: center;">
            <thead><th>编号</th><th>姓名</th><th>年龄</th><th>性别</th></thead><tbody>
        <?php
            $coon =coonectDb();
            $db=mysqli_select_db($coon, "myapp");
            mysqli_query($coon, "set names 'utf8'");
            $sql="select * from users";
            $result=mysqli_query($coon, $sql);
            $row=mysqli_num_rows($result);
            for($i=0;$i<$row;$i++)
            {
             $info=mysqli_fetch_assoc($result);
             $id=$info['id'];
             $name=$info['name'];
             $age=$info['age'];
             $sex=$info['sex'];
            
             echo "<tr> <td>$id</td> <td>$name</td> <td>$age</td> <td>$sex</td></tr>";
            }
            ?>
                        
        </tbody></table>
    </body>
</html>

//functions.php (类方法)

    require_once 'config.php';
    function coonectDb(){
        return mysqli_connect(mysql_host, mysql_user, mysql_pw);
    }

//config.php(基本配置)

<?php
    define('mysql_host','localhost');
    define('mysql_user','root');
    define('mysql_pw','');   
    ?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值