数据表结构:
表名:test
id name age
1 胡大 21
2 王二 22
3 张三 23
4 李四 24
5 孙五 25
6 钱六 26
7 牛七 27
8 周八 28
9 郑九 29
10 赵屎 30
PHP代码(test.php):
<?php
header("Content-type: text/html; charset=utf-8");
//引入medoo
require_once 'medoo.php';
use MedooMedoo;
$page = ($_GET["page"]-1)* $_GET["limit"];//数组以0起始
$limit = $_GET["limit"];
$id = $database->select("test","id", ["LIMIT" => [$page , $limit]]);//根据分页获取ID
$list = $database->select("test","*", ["id" => $id]);//请求数据库数据
//加工:
print_r($list); //输出数组
echo "<hr/>";
//循环遍历
foreach($list as $key=>$value){
extract($list[$key]);
echo "ID:".$id."姓名:".$name."值:".$age."<br/>";
}
?>
使用方法:
显示效果:
Array ( [0] => Array ( [id] => 1 [name] => 胡大 [age] => 21 ) [1] => Array ( [id] => 2 [name] => 王二 [age] => 22 ) [2] => Array ( [id] => 3 [name] => 张三 [age] => 23 ) [3] => Array ( [id] => 4 [name] => 李四 [age] => 24 ) [4] => Array ( [id] => 5 [name] => 孙五 [age] => 25 ) )
ID:1姓名:胡大值:21
ID:2姓名:王二值:22
ID:3姓名:张三值:23
ID:4姓名:李四值:24
ID:5姓名:孙五值:25
Array ( [0] => Array ( [id] => 6 [name] => 钱六 [age] => 26 ) [1] => Array ( [id] => 7 [name] => 牛七 [age] => 27 ) [2] => Array ( [id] => 8 [name] => 周八 [age] => 28 ) [3] => Array ( [id] => 9 [name] => 郑九 [age] => 29 ) [4] => Array ( [id] => 10 [name] => 赵屎 [age] => 30 ) )
ID:6姓名:钱六值:26
ID:7姓名:牛七值:27
ID:8姓名:周八值:28
ID:9姓名:郑九值:29
ID:10姓名:赵屎值:30
配合layui实现分页:
————————————————
版权声明:本文为CSDN博主「avenjan」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/avenjan/article/details/82425889
<?php
header("Content-type: text/html; charset=utf-8");
//引入medoo
require_once 'medoo.php';
use MedooMedoo;
$out= array('code' =>'0' ,"msg"=>"","count"=>"","data"=>"" );//定义返回数组
$page = ($_GET["page"]-1)* $_GET["limit"];//数组以0起始
$limit = $_GET["limit"];
$id = $database->select("test","id", ["LIMIT" => [$page , $limit]]);//根据分页获取ID
$list = $database->select("test","*", ["id" => $id]);//请求数据库数据
$out["count"]=$database->count("test");
$out["data"] = $list;
echo json_encode($out);
?>
效果:
Нет комментариев