简体   繁体   English

将选定的数据从表插入到另一个表

[英]Inserting selected data from table to another table

I want to add the selected data from table1 to another table2 here's my supposed output. 我想将表1中的选定数据添加到另一个表2中,这是我的假定输出。

Product Inventory List <-- displays the added product from 2nd table 产品库存清单<-显示第二个表中添加的产品

Product List <-- this one display the products from 1st table 产品列表<-此列表显示第一张表中的产品

In "Product List" I have my one listed product then if I click the "Add" Link, the data should be listed in the "Product Inventory List" 在“产品列表”中,我有一个列出的产品,然后,如果单击“添加”链接,则数据应列在“产品库存列表”中

Anyway here's my code for displaying the data of 1st table 无论如何,这是我的代码,用于显示第一张表的数据

<?php 
$product_list = "";
$sql = mysql_query("SELECT * FROM productinformation1 ORDER BY date_added DESC");
$productCount=mysql_num_rows($sql);
if($productCount>0){
    while($row = mysql_fetch_array($sql)){
        $id = $row["ProductNo"];
        $product_name = $row["ProdName"];
        $product_list .= "Product ID:&nbsp;$id - $product_name &nbsp; &nbsp;&nbsp; &nbsp; &bull; <a href='#'>Edit</a><br>";
    }
}else{
    $product_list = "You have no products listed in your store yet.";
}

?>

And here's my code for displaying the data of 2nd table 这是我的代码,用于显示第二张表的数据

<?php
$productsDB = "";
$sql1 = mysql_query("SELECT * FROM productinformation");
$productDBcount=mysql_num_rows($sql1);
if($productDBcount>0){
        while($row = mysql_fetch_array($sql1)){
        $id1 = $row["ProductNo"];
        $product_name = $row["ProdName"];
        $productsDB .= "Product ID:&nbsp;$id1 - $product_name &nbsp; &nbsp; &bull; <a href='product-add.php'> Add </a><br>";
        }
    }else{
    $productsDB = "You have no products listed in your store yet.";
}

?>

As you can see in displaying the data of 2nd table there's a link which is the "Add" and now I want that link function as well.. 正如您在显示第二个表的数据中看到的那样,有一个链接是“添加”,现在我也希望该链接功能。

And I don't know how get the data of 1st table and insert it in 2nd table so that it will this display in my "Product Inventory List" 而且我不知道如何获取第一张表的数据并将其插入第二张表,以便将其显示在我的“产品库存清单”中

Please help me. 请帮我。

your link should look like: 您的链接应如下所示:

<a href='product-add.php?idtoadd=".$id1."'> Add </a>

and in product-add.php you will be able to do: 在product-add.php中,您可以执行以下操作:

$sql = "insert ignore into productinformation1 (ProductNo, ProdName)
select ProductNo, ProdName from productinformation
where ProductNo = " . intval($_GET['idtoadd'], 10);

NOTE1: do not use mysql_### functions, use PDO or mysqli 注意1:不要使用mysql _ ###函数,请使用PDO或mysqli

NOTE2: do not use single quotes in HTML attributes, use double quotes 注意2:不要在HTML属性中使用单引号,而应使用双引号

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM