表格1


  两栏>>已付款-order_num1


表2


  两栏>> order_num2


我想从order_num2获取table 2值,

update paid(insert paid = 1) in table one with same order_num value


如果order_num1=order_num2,则表1中的paid = 1

$q = mysql_query("select order_num2 from table2 where samevalue = samevalue ");
$x = mysql_fetch_row($q);
mysql_query("update table1 set paid=1 where order_num1='$x['order_num2']'");


但这行不通!
如果order_num具有相同的值,则首先从一个表获取并从另一表更新支付

最佳答案

尝试

$table2 = mysqli_query("SELECT * FROM table2");
$row = mysqli_fetch_array($table2);
$num2 = $row['order_num2'];

$table1 = mysqli_query("SELECT * from table1");
$roww = mysqli_fetch_array($table1);
$num1 = $row['order_num1'];

if ($num2 == $num1) {
$updateDB = mysqli_query("UPDATE table1 SET paid = 1 WHERE order_num1 = '$num2'");
} else {
//Not equal so the paid column wont get updated
}

关于php - 如何获取并比较两个mysql数据?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23739725/

10-11 07:59