简体   繁体   English

如何将数据表中的所选行复制到数据库mysql中的另一个表

[英]how to copy the selected row in datatable to another table in database mysql

i have data in products in database and it all display to my datatable in php file. 我在数据库中的产品中有数据,所有数据都显示到php文件中的数据表中。 and now i have the selected rows in datatable and i want all the selected rows transfer to another table in database like from products to sales_order_holder when clicking the submit button. 现在我在数据表中有选定的行,并且我希望所有选定的行在单击“提交”按钮时都转移到数据库中的另一个表,例如从产品到sales_order_holder。 is it possible? 可能吗? .

<table id="example" cellspacing="0" width="100%" class="display">
  <thead>
    <tr>
      <th></th>
      <th>Category</th>
      <th>Brand</th>
      <th>Model</th>
      <th>Item Name</th>
      <th>Price</th>
      <th>id</th>
    </tr>
  </thead>
  <tbody>
    <?php do { ?>
    <tr>
      <td><?php echo ++$i; ?></td>
      <td><?php echo $row_products['pid']; ?></td>
      <td><?php echo $row_products['brand']; ?></td>
      <td><?php echo $row_products['model']; ?></td>
      <td><?php echo $row_products['item_name_']; ?></td>
      <td><?php echo $row_products['price']; ?></td>
      <td><?php echo $row_products['id']; ?></td>
    </tr>
    <?php } while ($row_products = mysql_fetch_assoc($products)); ?>
  </tbody>
</table>

Use this, 用这个,

INSERT INTO table2 (col1,col2...)
SELECT * FROM table1 WHERE selected row's id

If more than 1 row is selected, try using foreach or use INSERT BATCH to insert and WHERE IN in select 如果选择了多于1行,请尝试使用foreach或使用INSERT BATCH进行插入,并在select中使用WHERE IN

INSERT INTO table2 (val1, val2)
SELECT val1,val2 FROM table1 WHERE tableRowId = someID

You can have a check box beside each row in the displayed table.These checkboxes should contain the id of the product as value. 您可以在显示的表格的每一行旁边都有一个复选框。这些复选框应包含产品ID作为值。 Then pass on the values of these checkboxes using ajax to some php script which will run the query. 然后使用ajax将这些复选框的值传递给将运行查询的php脚本。

$(document).ready(function() {
$("#submit").click(function() {
  var x=0;
   console.log("start");

    var selected = [];
    $("input:checkbox[id=product]:checked").each(function(){
    selected.push($(this).val());
    });
    if (typeof selected !== 'undefined' && selected.length > 0) {

      var target= $("#target").val() ;
      var data = {
        products : selected.toString(),

    }



    $.ajax({
     url:"/dispatch",
     type: "POST",
     data:JSON.stringify(data),
     dataType: "json",
     contentType: "application/json",
     success: function(data)
     {           
            console.log("end");

     }
});

      }

});
});

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

相关问题 如何将MySQL数据库表的一行链接到另一个表的另一行 - How to link a row of MySQL database table to another row in another table 如何将表从一个mysql数据库复制到另一个mysql数据库 - How to copy a table from one mysql database to another mysql database MySQL-如何选择未在另一个表中选择的行 - MySQL - How to select row were not selected in another table 将选定的dataTable行传递到另一个php页面中的另一个dataTable行 - Pass selected dataTable row to another dataTable row in another php page 突出显示表的选定行(该表由PHP从MySQL数据库生成) - Highlight selected row of the table (table is generated by PHP from MySQL database) 如何使用Jquery和PHP将行复制到MySQL中的另一个表? - How do I copy a row to another table in MySQL using Jquery and PHP? 如何在PHPMyAdmin MySQL的同一表中将值从一行复制到另一行 - How to copy values from one row to another in the same table in PHPMyAdmin MySQL [MySql]如何将一行从一个表复制到另一个表并填充额外的列? - [MySql]How to copy a row from one table to another and fill additional columns? 如何将mysql数据库中的选定值与另一个表中的现有值进行比较? - How to compare a selected value from mysql database with an existing one in another table? MySQL:将postid从一个表复制到同一数据库中的另一个表 - MySQL: Copy postid from one table to another in same database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM