2014-05-19 26 views
0

表1如何獲取並比較兩個mysql數據?

兩個列>>支付 - order_num1

表2

兩個列>> order_num2

我想要得到從值和

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

如果order_num1=order_num2然後paid = 1表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具有相同的價值得到

+0

我試過,但我認爲它不夠清晰,以幫助您 – nicowernli

+0

其中table1.column = table2.column ? –

+0

請澄清你的問題,我不明白 –

回答

0

嘗試

$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 
}