根据要求分页(按用户要求分页记录) [英] On request pagination(Paginate records on demand of user)

查看:69
本文介绍了根据要求分页(按用户要求分页记录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个基于某些过滤器的网格上显示记录数.当用户单击网格底部的链接 Show More 时,我想对它们进行分页.进行搜索,但是找不到页面编号的东西或某种自动滚动.但是,如何在我的方案中工作? 到目前为止,我的研究是,我必须编写链接的 onclick 函数,使用ajax获取记录的下一批(每个请求说20条记录).编程部分将如何工作.我在服务器端使用 PHP ,并在数据库中使用 Mysql 有人可以指导我.谢谢您的时间.

I am working on a grid which displays number of records,based on some filters.I want to paginate those,when the user clicks on a link Show More at the bottom of grid.I tried for a search but,either found the page number stuff or some kind of auto scroll.But,how can I get to work in my scenario? What my research till now is,I will have to write a function onclick of the link,fetch the next batch of records(say 20 on each request) using ajax.But how would the programing part work.I am using PHP at the server end and Mysql as my DB Can someone guide me on it.Thanks for your time.

推荐答案

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

if(isset($_GET['dark']))
{
    $max_result=$_GET['dark'];

}
else
{
    $max_result=5;
}

$from=(($page*$max_result)-$max_result);

mysql_select_db("db",$con);
$sql = "SELECT COUNT(*) FROM `db`.`table` ";
$result=mysql_query($sql);

$total_result=mysql_result($result,0);
$total_pages=ceil($total_result/$max_result);

if($total_result>$max_result)
{
    if($page>1)
    {
        $prev=$page-1;
        echo "<a href=\"".$_SERVER['PHP_SELF']."?dark=".$max_result."&page=$prev\">previous</a>";
    }
    for($i=1;$i<=$total_pages;$i++)
    {
        if($page==$i)
        {
        echo "<strong>".$i."</strong>";
        }
        else
        {
        echo "<a href=\"".$_SERVER['PHP_SELF']."?dark=".$max_result."&page=$i\">$i</a> ";
        }
        if($page<$total_pages)
        {
        $next=$page+1;

        //echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";
        }
    }

        if($page<$total_pages)
        {
                $next=$page+1;
                echo "<a href=\"".$_SERVER['PHP_SELF']."?dark=".$max_result."&page=$next\">next</a>";
        }
}

         echo "<table><tr>";

            echo "<td><form action='helloworld.php' name='get'>
                <select name='dark'>
                <option value='2'>2</option>
                <option value='5'>5</option>
                <option value='10'>10</option>
                </select>
                <input type='hidden' name='searching' value='yes' /><input type='submit' value='No.of entries'>
                </form></td></tr>";         
            echo "<tr><td><strong>PAGE NUMBER $page of $total_pages.</strong>.</td></tr>";
            echo"</table>";

这篇关于根据要求分页(按用户要求分页记录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆