简体   繁体   English

PHP的下一页和上一页从MySQL获取数据

[英]Php Next page and Previous page fetch data from mysql

am using search items to filter the city,gender,profession and state. 正在使用搜索项过滤城市,性别,行业和州。 it should display 3 rows per page. 每页应显示3行。 but it display the first page. 但它显示第一页。 when i presss the last page, again it comes back to home page. 当我按最后一页时,它又回到首页。

<?php
if(isset($_POST['submit']))
{                           
    $con = mysql_connect("localhost","root","");

    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("nursingcarein",$con);

    if (isset($_GET["page"])) {
        $page  = $_GET["page"]; 
    } else { 
        $page=1; 
    };

    $start_from = ($page-1) * 3;
    /*pass the values(city,gender,profession,state) frm search */

    $city=$_POST['city'];

    $gender=$_POST['gender'];

    $profession=$_POST['profession'];

    $state=$_POST['state'];

I'm not sure if this is your problem but the following code : 我不确定这是否是您的问题,但是下面的代码:

LIMIT $start_from, 3

Does not work if $start_from is greater than 3. If you want 3 records, you have to do this : 如果$start_from大于3,则不起作用。如果要3条记录,则必须这样做:

$end = $start_from + 3;
// Your code here
LIMIT $start_from, $end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM