2

我相信他们可能是更好的方法......是否可以使用加载更多按钮将项目形式复制table1(column)到25 个数据行块中?table2(column)

我该怎么做?我在哪里可以找到这方面的信息?谢谢你。

4

1 回答 1

1

我希望这能帮到您。您可以在 php 中实现它以加载更多操作。

每次单击更多按钮后,在mysql查询中更改偏移量和限制

INSERT INTO table2 SELECT * FROM table1 LIMIT 0, 25;

load more...

INSERT INTO table2 SELECT * FROM table1 LIMIT 25, 25;

load more...

INSERT INTO table2 SELECT * FROM table1 LIMIT 50, 25;

……

……

完整的代码。

1.只需将以下代码复制并粘贴到page1.php中

<div id='message'></div>

<a href='#' id='LoadMore' >Load More</a>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"
    type="text/javascript"></script>

<script>
$(function() {
    var page = 1;
    $("#LoadMore").click(function(){
        $.ajax({
            type:"GET",
            url:"page2.php",
            data:{page:page},
            success: function(response) {
                $("#message").append(response); 
                page++;
            }
        });
    }); 
});
</script>

2.在page2.php中复制以下代码

并在前两行更改 mysql_server、mysql_user、mysql_password、database_name 参数

<?php
//set argument as your mysql server
$connect = mysql_connect("mysql_server","mysql_user","mysql_password");
mysql_select_db("database_name",$connect);

$page = isset($_GET["page"]) ? $_GET["page"] : 1;
$limit = 25;
$offset = ($page - 1) * $limit;

$sql = "INSERT INTO table2 SELECT * FROM table1 limit $offset, $limit";
mysql_query($sql);
$rows = mysql_affected_rows();
echo "$rows rows added to table2 from table1<br>";
?>

3.在浏览器中运行page1.php...并将数据加载到table2

现在显示来自 table2 的数据,无需根据需要刷新页面(user2714387 在评论中说)

4.将以下代码复制粘贴到page3.php中

<table width="300" border="1" id='data_grid'></table>

<a href='javascript://' id='LoadMore' >Load More</a>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"
    type="text/javascript"></script>

<script>
$(function() {
    var page = 1;
    $("#LoadMore").click(function(){
        $.ajax({
            type:"GET",
            url:"page4.php",
            data:{page:page},
            success: function(response) {
                $("#data_grid").append(response); 
                page++;
            }
        });
    }); 
});
</script>

4.在page4.php中复制以下代码

<?php
    //set argument as your mysql server
    $connect = mysql_connect("mysql_server","mysql_user","mysql_password");
    mysql_select_db("database_name",$connect);

    $page = isset($_GET["page"]) ? $_GET["page"] : 1;
    $limit = 25;
    $offset = ($page - 1) * $limit;

    $sql = "SELECT * FROM table2 limit $offset, $limit";
    $result = mysql_query($sql);
    $numRows = mysql_num_rows($result);
    if($numRows>0) {
        while($row = mysql_fetch_array($result)) {
            //get field data and set to the following row
            echo "<tr><td>field 1</td><td>field 2</td><td>field 3</td></tr>";
                    //edit row as you table data

        }
    } else {
        echo "<tr><td colspan='3'> No more data </td></tr>";
    }
    exit;
?>

6.在浏览器中运行page4.php

于 2013-09-02T05:03:09.690 回答