简单的面向过程分页

<?php
$pdo    =    new PDO('mysql:host=127.0.0.1;dbname=lianxi','root','root');
$page   =    isset($_GET['page'])?$_GET['page']:1;
$sql2   =    "select * from one";
$count  =     count($pdo->query($sql2)->fetchAll(PDO::FETCH_ASSOC));//记录总条数数量
$lenth  =     3; // 每一页显示条数
$zys    =     ceil($count/$lenth);
$pyl    =     ($page-1)*$lenth;  //偏移量
$pdo   ->     exec('set names utf8');
$up    =      $page<=1?1:$page-1;
$next  =      $page+1>=$zys?$zys:$page+1;
$sql   =      "select * from 表名字 limit $pyl,$lenth";
$arr   =      $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<form action="9.222.php" method="post">
    <input type="text"name="name"/>
    <input type="submit"value="查询"/>
<table border="1">
    <tr>
        <td>编号</td>
        <td>名字</td>
        <td>密码</td>
        <td>时间</td>
        <td>状态值</td>
    </tr>
    <?php foreach ($arr as $key => $val ){ ?>
    <tr>
        <td><?php echo $val['id']?></td>
        <td><?php echo $val['name']?></td>
        <td><?php echo $val['pwd']?></td>
        <td><?php echo $val['time']?></td>
        <td><?php echo $val['sta']?></td>
    </tr>
    <?php }?>
</table>
    <a href="9.22.php?page=1">首页</a>
    <a href="9.22.php?page=<?php echo $up ?>">上一页</a>
    <a href="9.22.php?page=<?php echo $next?>">下一页</a>
    <a href="9.22.php?page=<?php echo $zys?>">尾页</a>
</form>
</body>
</html>
自主封装的PHP ORM框架,面向对象的PDO数据库操作,API框架,支持Get/Post/Put/Delete多种请求方式。 代码示例: <?php use Models\User; require '../application.php'; require '../loader-api.php'; //适合查询,如:获取用户列表或者单个用户信息 execute_request(HttpRequestMethod::Get, function() { $action = request_action(); //判断是否存在 if ($action == 1) { list($type, $value) = filter_request(array( request_int('type', 1, 2, 3), //1.用户名 2.邮箱 3.手机号 request_string('value'))); $type_field_map = array( 1 => User::$field_username, 2 => User::$field_email, 3 => User::$field_phone ); if ($type == 2 && !is_email($value) || $type == 3 && !is_mobilephone($value)) { die_error(USER_ERROR, $type_field_map[$type]['name'] . '格式无效'); } $user = new User(); $user->set_where_and($type_field_map[$type], SqlOperator::Equals, $value); $result = $user->exists(create_pdo()); echo_result($result ? 1 : 0); //存在返回1,不存在返回0 } //查询单条信息 if ($action == 2) { list($userid) = filter_request(array( request_userid())); //查询单条数据 $user = new User($userid); //set_query_fields可以指定查询字段,下面两种写法均可 //$user->set_query_fields('userid, username, email'); //$user->set_query_fields(array(User::$field_userid, User::$field_username, User::$field_email)); //还可设置where条件进行查询 //$user->set_where_and(User::$field_status, SqlOperator::Equals, 3); //$user->set_where_and(User::$field_truename, SqlOperator::IsNullOrEmpty); //$user->set_where_and(User::$field_age, SqlOperator::In, array(27, 29)); //$user->set_where_and(User::$field_regtime, SqlOperator::LessThan, '-6 month'); //创建数据库连接 $db = create_pdo(); $result = $user->load($db, $user); //也可以用Model类的静态方法 //$result = Model::load_model($db, $user, $user); if (!$result[0]) die_error(PDO_ERROR_CODE, '获取用户信息时数据库错误'); if (!$user) di
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值