dongtang4954 2015-11-27 06:45
浏览 80

如何在不加载整个页面的情况下加载更多帖子?

In my home page, I'm showing the last three rows of my table via this code:

$result = mysql_query("SELECT  id, title, date, text FROM news WHERE hshs=1 ORDER BY date DESC LIMIT $p") or die(mysql_error());

Where $p comes from:

$p = $_GET['page'];

if ( empty($p) ) {
    $p = 2;
    $more = 4;
} 
else{
    if ( $p < $postnum ) {
        $more = $p + 2;
    }
    else{
        $finish = 1;
    }       
}

and $postnum is number of the rows.

Then, I have this line to load more posts:

if ( $finish != 1 ) {
    echo '<center><strong><a id="loadmore" href="?page='.$more.'">Load more posts...</a></strong></center>';
}

This does its job beautifully. But I have a problem. I don't want to load the whole page again to load more posts. Because this will show the page again from the top of it! I want the page to stay where it is without scrolling the user to the top of it, and then loads more posts.

Hope you will understand me! :)

  • 写回答

2条回答 默认 最新

  • duanpao6163 2015-11-27 06:58
    关注

    Step 1) Call an Ajax request on click of "Load more posts..".

    Step 2) PHP will return more posts as response to Ajax request.

    Step 3) Append Ajax result in appropriate div (preferably using jQuery).

    Note: Use limit in MySQL query for proper paging mechanism.

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路