将另一个表中的行添加到另一个表中

时间:2014-05-05 09:38:13

标签: php mysql sql

假设我有我的餐桌产品(ID,名称,描述,图片,价格)。我有另一个表product_add(id,name,price)。 我从表格产品中选择了所有并显示它

以下是显示表格产品

中所有数据的代码
    <html>
    <head>     
    <script type="text/javascript" src="add.js"/>
    </head>
    <?php
    include'dbConnect.php';    
    $image =$_GET['image'];
    $id = $_GET['id'];
    $name = $_GET['name'];
    $price= $_GET['price'];

    $sql="SELECT * FROM product";

    $result = mysql_query($sql);
    echo sizeof($result);

    if($result>0){
        echo "<table border='1'>
        <tr>
        <td>ID</td>
        <td>Image</td>
        <td>Name</td>
        <td>Price MUR</td>
        </tr>";

        while ($row = mysql_fetch_array($result)){
            extract($row);

            //creating new table row per record
            echo "<tr>";
            echo "<td>$id</td>";
            echo "<td><img src=$image  width='120' height='100'/></td>";
            echo "<td>$name</td>";
                echo "<td class='textAlignRight'>$price</td>";
                echo "<td class='textAlignCenter'>";
    ?>
                <input type='button' name='Add_value' value='Add to Cart' onclick='addfunction()'/>
<?php
        }//end while
            echo "</table>";        

    }
    $insert = "INSERT INTO product_add(id, name, price) VALUES ('$id', '$name','$price' ) ";
    $insertQuery=mysql_query($insert);
    ?>
        <div id='ajaxDiv'>Your result will display here</div>
    </html>

但问题是,当我点击Add to cart按钮时,每当我将特定产品添加到购物车时,只有最后一行被添加到product_add表。

0 个答案:

没有答案