怎么把MySQL内容显示到网页中_如何将数据库中数据提取出来然后显示到网页中...

$sql = new mysqli(“localhost”,”用户名”,”密码”,”数据库”);

if(mysqli_connect_errno()){

echo “cnnect_errno”;

exit;

}

$query = “select * from student”;

$result = $sql->query($query);

$num_results = $result->num_rows;//总页数

$cpage = isset($_GET[“page”]) ? $_GET[“page”] :1; //当前页

$num = 10; //每页的页数

$url = “fen_ye.php”;//每次请求你的页面

$offset=($cpage-1) * $num;//数据读取的位置

$pagenum = ceil($num_results/$num);//总页数

$query = “select * from student limit {$offset},{$num}”;//取数据

$result = $sql->query($query);

$num_results = $result->num_rows;

//每一页的的开始与结尾

$start = $offset + 1;

$end=($cpage==$pagenum)? $num_results : ($cpage*$num);

// 上一页 和 下一页

$next=($cpage==$pagenum)? 0 : ($cpage+1);//如果页面到了结尾 就返回0 就是不在下一页了

$prev=($cpage==1) ? 0 : ($cpage – 1);

for($i = 0; $i

$row = $result->fetch_assoc();

echo “

echo “

“;

echo “

{$row[“cno”]}”;

echo “

{$row[“name”]}”;

echo “

{$row[“age”]}”;

echo “

{$row[“sex”]}”;

echo “

“;

echo “

“;

}

echo “

echo “

“;

echo “

当前页总数:{$num_results}”;

echo “

本页条数:{$start}-{$end}”;

echo “

页面位置:{$cpage}/{$pagenum}”;

if($cpage == 1){

echo “

首页”;

}else{

echo “

首页;”;

}

if($prev){

echo “

上一页“;

}else{

echo “

上一页”;

}

if($next){

echo “

下一页“;

}else{

echo “

下一页”;

}

if($cpage == $pagenum){

echo “

尾页”;

}else{

echo “

尾页“;

}

echo “

“;

echo “

“;

?>

    原文作者:瑾欢
    原文地址: https://blog.csdn.net/weixin_42493720/article/details/113391869
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞