💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 常规获取 第一步:获取数据 ``` //状态排序 if ($_GET['status'] > 0) { $status = "status=" . $_GET['status']; } else { $status = "status>0"; } //数据查询 if ($_POST['type'] != '') { $search = "{$_POST['type']}='{$_POST['search']}'"; } else { $search = '1'; } //获取数据总量 $count = DB('shop_project')->where("$status and $search")->getCount(); //每页显示数量 $pagesize = CP_SYS_PAGES; //获取页数 $pages = ceil($count / $pagesize); //当前页码 if (isset($_GET['page'])) { $page = intval($_GET['page']); } else { $page = 1; } //获取开始 $offset = $pagesize * ($page - 1); //分页是否可点 if ($pages < 2) { $class = 'disabled'; } else { $class = null; } //获取数据集 $rows = DB('shop_project')->where("$status and $search")->order('sort asc')->limit($offset, $pagesize)->select(); ``` 第二步:展示与分页 1、数据列表展示 ``` foreach ($rows as $res) { if ($res['status'] == 1) { $status = '<font color="green">正常</font>'; } elseif ($res['status'] == 2) { $status = '<font color="red">停用</font>'; } echo '<tr>' . '<th><input class="form-control" style="width: 48px;" type="text" name="sort" value="' . $res['sort'] . '"> <input type="hidden" name="id" value="' . $res['id'] . '"></th>' . '<th>' . $res['id'] . '</th>' . '<th>' . $res['name'] . '</th>' . '<th></th>' . '<th></th>' . '<th>' . app::cout(app::clear_all($res['info']), 30) . '</th>' . '<th>' . $status . '</th>' . '<th>' . '<a href="?do=edit&id=' . $res['id'] . '" class="btn btn-sm btn-info btn-addon"><i class="fa fa-edit"></i>编辑</a> ' . '</th>' . '</tr>'; } ``` 2、分页代码 ``` <?= pages($page, $class, $pages, '&status=' . $_GET['status']) ?> ``` ***** # 多表查询 其它方法同上【常规获取】 获取数据如下: ``` //状态排序 if ($_GET['status'] > 0) { $status = "a.status=" . $_GET['status']; } else { $status = "a.status>0"; } //数据查询 if ($_POST['type'] != '') { $search = "a.{$_POST['type']}='{$_POST['search']}'"; } else { $search = '1'; } //获取数据总量 $sql = "SELECT b.name AS gname,b.info AS ginfo,a.* FROM {$_tb}shop_project AS a LEFT JOIN {$_tb}shop_project_type AS b ON a.tid = b.id WHERE $status and $search"; $count = DB()->execute($sql); //每页显示数量 $pagesize = CP_SYS_PAGES; //获取页数 $pages = ceil($count / $pagesize); //当前页码 if (isset($_GET['page'])) { $page = intval($_GET['page']); } else { $page = 1; } //获取开始 $offset = $pagesize * ($page - 1); //分页是否可点 if ($pages < 2) { $class = 'disabled'; } else { $class = null; } //获取数据集 $sql = $sql . " ORDER BY a.sort asc LIMIT " . $offset . " , " . $pagesize; $rows = DB()->query($sql); ```