Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在页面滚动中动态检索数据到div_Php_Jquery_Ajax_Html - Fatal编程技术网

Php 如何在页面滚动中动态检索数据到div

Php 如何在页面滚动中动态检索数据到div,php,jquery,ajax,html,Php,Jquery,Ajax,Html,我一直在寻找一个答案几个小时没有运气,所以我决定来这里 我希望当用户滚动到页面底部时,页面能够将数据从数据库动态加载到 每一组新数据应在最后一组数据后保留5条记录 如果有人能抽出时间看看我的密码,我将永远感激 这是我的代码: 加载 身体{ 字体系列:helvetica; 背景色:#58ACFA; 宽度:100%; } h1{ 文本对齐:居中; 字体大小:35px; 边缘顶部:50px; 颜色:#0B173B; } #所有行{ 溢出y:滚动; 高度:400px; } #装载{ 边框:1.5px

我一直在寻找一个答案几个小时没有运气,所以我决定来这里

我希望当用户滚动到页面底部时,页面能够将数据从数据库动态加载到

每一组新数据应在最后一组数据后保留5条记录

如果有人能抽出时间看看我的密码,我将永远感激

这是我的代码:


加载
身体{
字体系列:helvetica;
背景色:#58ACFA;
宽度:100%;
}
h1{
文本对齐:居中;
字体大小:35px;
边缘顶部:50px;
颜色:#0B173B;
}
#所有行{
溢出y:滚动;
高度:400px;
}
#装载{
边框:1.5px黑色实心;
高度:200px;
宽度:100px;
背景色:#0B3861;
颜色:白色;
填充:20px;
边缘顶端:40px;
字体大小:20px;
}
$(“#所有_行”)。滚动(函数()
{

如果($(“#load”).height()使用下面我给你的简单示例代码:

<html>
<head>
</head>
<body>
<div id="userData">
</div>
</body>
</html>
函数加载更多数据

function loadMoreData(last_id) {
    $.ajax(
        {
            url: 'get_results.php?last_id=' + last_id ,
            type: "get",
            beforeSend: function () {
                $('.ajax-load').show();
            }
        })
        .done(function (data) {
             $('.ajax-load').hide();
            $("#userData").append(data);
        })
        .fail(function (jqXHR, ajaxOptions, thrownError) {
            console.log('server not responding...');
        });
}
在控制器上,您接收ID并选择大于当前接收ID的数据

 $(window).scroll(function () {
    if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
        var last_id = $("#userData a:last-child").attr('id');
        if(last_id == "" || last_id == undefined)
        {
           last_id=0;
         }
        loadMoreData(last_id);
    }
});
** 
    <?php

      if(isset($_GET['last_id']))
      {
        $conn = mysqli_connect("localhost", "id5757217_testsql01", "9977553311", "id5757217_testsql1");
            if ($conn->connect_error) {
                die("Connection failed: " . $conn->connect_error);
    }

 if($lastId!=0){
    $sql = ("SELECT * FROM insertion where id < '" . $lastId . "' ORDER BY id DESC LIMIT 5");
}else{
    $sql = ("SELECT * FROM insertion ORDER BY id DESC LIMIT 5");
}    
        $result = $conn->query($sql);
        while ( $row = $result-> fetch_array()) {
            echo "<div id = 'load'>";
            echo "<div id = 'load1'>" . $row['Title'] . "</div>";
            echo "<div id = 'load2'>" . $row['Description'] . "</div>";
            echo "<div id = 'get'>" . "<a href = '" .  $row['Link'] . "' target = '_blank' id =  '" .  $row['id'] . "'> Get This file </a> </div>";
            echo "</div>";
          }
        exit();
      }
     ?>

我很快就会试试。谢谢