简体   繁体   English

PHP / MySQL通过“加载更多”按钮将数据从一个表中大块复制到另一个表中

[英]PHP/MySQL copy data in chunks from one table to another via a load more button

I am sure their is probably a better way... Is it possible to copy items form table1(column) to table2(column) in data row chunks of 25 with a load more button? 我确信它们可能是更好的方法...是否可以通过加载更多按钮将数据table2(column)项从table1(column)复制到table2(column) ,数据行的块数为25?

How would I do this? 我该怎么做? Where would I find information on this? 我在哪里可以找到有关此信息? Thank you. 谢谢。

I hope this will help you. 我希望这能帮到您。 You can implement it in php to load more action. 您可以在php中实现它以加载更多操作。

every time after clicking more button change offset and limit in mysql query 每次单击更多按钮后,更改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;

.... ....

.... ....

Commplete code. 完整的代码。

1.Just copy and paste following code in page1.php 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.Copy following code in page2.php 2.将以下代码复制到page2.php中

and change mysql_server, mysql_user, mysql_password, database_name argument in first two line 并在前两行更改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.Run page1.php in browser... and load data to table2 3.在浏览器中运行page1.php ...并将数据加载到table2

Now showing data from table2 without refreshing page as required (user2714387 said in comment) 现在显示来自table2的数据,而无需按要求刷新页面(user2714387在评论中说)

4.Copy and paste following code in page3.php 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.Copy following code in page4.php 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.Run page4.php in browser 6,在浏览器中运行page4.php

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

相关问题 PHP / MySQL:将表和数据从一个数据库复制到另一个数据库 - PHP/MySQL: Copy Table and Data from one Database to another 在 PHP 和 MySQL 中将地理数据从一个表复制到另一个表 - Copy geo data from one table to another in PHP and MySQL 如何从一个表数据复制列到另一表并在mysql中同时插入更多列? - how to copy column from one table data to another table and insert more columns same time in mysql? 当数据相交时使用PHP将数据从一个MySQL表复制到另一个 - Copy data from one MySQL table to another when data intersect using PHP MySql中如何将列数据从一张表复制到另一张表? - How to Copy Column data from one table to another table in MySql? PHP和mysql将记录从一个表复制到另一个表 - php and mysql copy record from one table to another 在PHP和MySQL中仅将特定行从一个表复制到另一个表 - Copy only specific rows from one table to another in PHP and MySQL 如何在MySQL中将数据从一个表复制到另一个表? - How to copy data from one table to another in MySQL? 将数据从一个表复制到另一个表,并使用 laravel 中的一个按钮从主表中删除数据 - copy data from one table to another table and also delete data from main table with one button in laravel 如何将数据从一个表复制到另一个表? PHP - How copy data from one table into another? PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM