-1
如何比較同一數據庫中的2個表格數據。例如:如何比較2個表格的數據?
Table 1:
--------
Order number, user_id etc
Table 2:
--------
Order number
=>一個用戶可以製作多個訂單。所以我需要使用表2訂單號檢查用戶的所有訂單。如果找到,那麼它將被打印爲true,否則爲false。我嘗試下面的代碼:
$user = JFactory::getUser();
$user_id= $user->get('id');
$db = JFactory::getDbo();
$db->setQuery("SELECT virtuemart_user_id, order_number, order_total, created_on FROM `#__virtuemart_orders` WHERE `virtuemart_user_id`='$user_id' AND `order_status`='C'");
$row = $db->loadRowList();
foreach($row as $d){
// I NEED TO COMPARE THE LOGIC HERE WITH THE SECOND TABLE. If it found match
// with table 2 then another column will be created & print out that
// "We found your order"
echo "<tr>";
echo "<td><a href='index.php?option=com_virtuemart&view=orders&layout=details&order_number=".$d['1'] ."'target='_blank'>".$d['1']."</a></td>";
echo "<td><a href='index.php?option=com_virtuemart&view=orders&layout=details&order_number=".$d['1'] ."'target='_blank'>".$d['2']."</td>";
echo "<td><a href='index.php?option=com_virtuemart&view=orders&layout=details&order_number=".$d['1'] ."'target='_blank'>".$d['3']."</td>";
echo "</tr>";
}
感謝您的回覆。但主要問題是表2中沒有主鍵。訂單號碼在FileValue字段中。我在foreach函數
中試過這段代碼。但我無法比較每個訂單。我的意思是,如果它與表1中的訂單編號5匹配,表2中的訂單編號相同,那麼它將在訂單編號旁邊打印成功的消息。 – jibon57好的,我得到了解決方案。 – jibon57