• php实现读取mySQLl数据库并进行最简单分页


    <html>

    <?php
    header("Content-type:text/html;charset=utf-8");//中文防止乱码
    error_reporting(0);
    $page=$_GET['p'];
    //$pageSize='5';

    $host="127.0.0.1";
    $username="root";
    $password="";
    $db="test";
    $conn=mysql_connect($host,$username,$password);
    if(!$conn)
    {
    echo "数据库连接失败";
    exit;
    }
    mysql_select_db("test");
    mysql_query("set names utf8");
    $sql="SELECT * FROM exam LIMIT"." " .($page-1)*10 .",10";//每个页面读取10条数据
    //$sql="SELECT * FROM exam LIMIT ".($page-1)*$pageSize.",$pageSize";
    $result=mysql_query($sql);
    while($row=mysql_fetch_assoc($result))
    {
    echo "<table border=1 cellspacing=0 width=40%>";
    echo ($row['id']);
    echo '&nbsp';
    echo ($row['name']);
    echo "</table>";
    }
    mysql_free_result($result);
    mysql_close($conn);


    $page_banner = "<a href=" .$_SERVER['PHP_SELF'].'?p='.($page-1). ">上一页</a>";

    $page_banner .= "<a href=" .$_SERVER['PHP_SELF'].'?p='.($page+1). ">下一页</a>";
    echo $page_banner;

    ?>
    </html>

    注释:test 数据库下的exam表  。

  • 相关阅读:
    check2
    LYF模板连接.txt
    mvc中的表现和数据分离怎么理解?
    node中websocket的使用
    vue随笔
    python安装Django常见错误
    node中的session的使用
    为什么很多IT公司不喜欢进过培训机构的人呢
    vue数据交互
    vuecli的服务代理
  • 原文地址:https://www.cnblogs.com/yjm5/p/5846890.html
Copyright © 2020-2023  润新知