• 分页查询


    1.引入两个类文件 连接数据库的类和分页类
    2.造对象 查询出所有条数 索引取 $tiaoshu=$attrn[0][0];
    3.根据条数查所有的数据 $page->limit

    4.判断提交的name值是否为空 将name值取出来判断是否为空 作为查询条件 拼在SQL语句上

    5.调用分页的方法

    <?php
    $name="";
    $tiaojian="";
    if(!empty($_GET["name"]))//判断传过来的name值是否为空
    {
    	$name=$_GET["name"];
    	$tiaojian="name={$name}";//查询条件
    	}
    $tj=" where AreaName like '%{$name}%' ";
    ?>
    <form action="biaoqian.php" method="get">
    请输入名称:<input type="text" name="name" value="<?php echo $name ?>"/>
    <input type="submit" value="查询"/>
    </form>
    <table width="100%" cellpadding="0" cellspacing="0" border="1">
    <tr>
    <td>代号</td>
    <td>姓名</td>
    </tr>
    <?php
    include("../DBDA.class.php");
    include("../page.class.php");
    $db=new DBDA();
    $sqln="select count(*) from chinastates".$tj;//查询条数
    $attrn=$db->Query($sqln);
    //var_dump($attrn);
    $tiaoshu=$attrn[0][0];//索引取所有的条数
    $page=new Page($tiaoshu,20,$tj,true);//需要参数 1.数据总条数(总条数$attr,一页显示多少20,查询条件,ture类型从第一页显示,)
    $sql="select * from chinastates ".$tj.$page->limit; 
    $attr=$db->Query($sql);
    foreach($attr as $v)
    {
    	echo"
    	<tr>
    	<td>{$v[0]}</td>
        <td>{$v[1]}</td>	
    	</tr>
    	";
    	}
    ?>
    </table>
    <?php
    echo"<div>".$page->fpage()."</div>";//调用分页的方法 fpage方法
    ?>
    

      

  • 相关阅读:
    DockerFile构建步骤及命令
    linux安装nginx及常用命令
    docker常用命令
    Docker安装
    获取TrustedInstaller权限
    获取本机公网ip的url地址
    centOS7配置ip
    VS Code配置c语言环境
    Linux l 2.4.20-8 # 溢出
    VMware Destination Host Unreachable
  • 原文地址:https://www.cnblogs.com/yuchao19950412/p/5622367.html
Copyright © 2020-2023  润新知