将跟踪ID从表2的列复制到表1的列

时间:2018-11-19 13:01:58

标签: php mysql forms

在下图中,单击第三列中的“ 提交”按钮后,我要将跟踪ID从表2的列复制到表1的列。...

订单

enter image description here

第4列中显示的跟踪ID”

enter image description here

我将订单信息保存在表 orders [Table 1]

enter image description here

我在表 awbno [表2]和 tracking_two

列中保存了跟踪ID

enter image description here

track.php

<?php

$con = mysqli_connect("localhost","root","","do_management4");

$result = mysqli_query($con,"SELECT * FROM orders");

echo "<table border='1'>
<tr>
<th>order</th>
<th>payment</th>
<th>generate</th>
<th>tracking id</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
echo "<tr>";
echo "<td>" . $row['order_id'] . "</td>";
    echo "<td>" . $row['payment_type'] . "</td>";

    echo "<td>";
    if (empty($row['tracking_one'])) {
        echo "<form method='post' action='call.php'>";
        echo "<input type ='hidden' name='id' value='$id'>
          <input type='submit'>
          </form>";
    }
    echo "</td>";
echo "<td>" . $row['tracking_one'] . "</td>";

echo "</tr>";
}
echo "</table>";

mysqli_close($con);

?>

call.php

<?php

$con = mysqli_connect("localhost","root","","do_management4");
$result = mysqli_query($con,"SELECT * FROM orders");

$id = $_POST['id']; 
$r = ""; 

$sql = $con->query("update orders set tracking_one = '$r' WHERE id ='$id'");
mysqli_close($con);

?>

我没有在Google中找到任何特定的查询,什么查询对我有帮助?

1 个答案:

答案 0 :(得分:1)

您的查询应该是这样的

$sql = $con->query("update orders set tracking_one = (select tracking_two from awbno WHERE id =$id)");