搜索两个表格,并以单一格式

时间:2017-01-06 05:12:33

标签: php mysql

我的table1table2

table1
+-------+-------------+---------+
| Nomor |   Name      |   Age   |
+-------+-------------+---------+ 
|  a1   | Supar       | 25      |
|  a2   | Rambo       | 23      |
+-------+-------------+---------+

table2
+-------+-------------+---------+
| Nomor |   Name      |   Age   |
+-------+-------------+---------+ 
|  b1   | Boneng      | 28      |
|  b2   | Dennyius    | 32      |
+-------+-------------+---------+

我想通过$Nomor创建搜索表单,以便从两个表格中更新数据$Name$Age

这里是我搜索n获取数据的代码:

if(isset($_POST['Search'])) {

    $NoMohon = $mysqli->real_escape_string($_POST['Nomor']);

    //query database
    $resultSet = $mysqli->query("SELECT * FROM table1 WHERE Nomor = '$Nomor' union SELECT * FROM table2 WHERE Nomor = '$Nomor'");

    if($resultSet->num_rows > 0) {
        while($rows = $resultSet->fetch_assoc()) {
            $Nomor = $rows['Nomor'];
            $Name = $rows['Name'];
            $Age = $rows['Age'];
        }
    } else {
        $output = "Data Null!";
    }
}

这是我更新表的代码:

if(isset($_POST['Save'])) {
    $Nomor = $mysqli->real_escape_string($_POST['Nomor']);

    //query database
    $resultSet = $mysqli->query("SELECT * FROM table1 WHERE Nomor = '$Nomor' union SELECT * FROM table2 WHERE Nomor = '$Nomor'");

        $Name = strtoupper($_POST['Name']);
        $Age = strtoupper($_POST['Age']);

        //NEED WORKING CODE HERE
        $sql = $mysqli->query("UPDATE table1 SET Name ='{$Name}', Age ='{$Age}' WHERE Nomor='$Nomor' union UPDATE table2 SET Name ='{$Name}', Age ='{$Age}' WHERE Nomor='$Nomor'");
        header('Location: going.php');
    }

如果我想将搜索结果b1名称Boneng更改为Bonanga2年龄23更改为{{1},如何使更新代码生效例如。抱歉,如果混淆。 THX

0 个答案:

没有答案