如何比较同一数据库中的 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>";
}