私の目標は、まだすべての製品を受け取っていない発注書のみを表示することです。
と呼ばれるマスターテーブルとtest_po
他の2つのテーブルtest_po_bom
がありtest_rog_bom
ます。およびテーブルは、製品のリストを格納する場所です test_po_bom
。は私が注文した製品のリストであり、は私が受け取った製品のリストです。test_rog_bom
test_po_bom
test_rog_bom
基本的に:loop purchase_orders WHERE products_received < products_ordered
テーブル構造:
table `test_po`: `ID`, `vendor_ID`
table `test_po_bom`: `ID`, `po_ID`, `product_ID`, `quantity`
table `test_rog_bom`: `ID`, `po_ID`, `product_ID`, `quantity`
コード:
$SQL = "SELECT
*,
test_po.ID AS test_po_ID
FROM
test_po
LEFT JOIN test_po_bom ON test_po_bom.po_ID=test_po.ID
LEFT JOIN test_rog_bom ON test_rog_bom.po_ID=test_po.ID
WHERE
(SELECT SUM(quantity) FROM test_rog_bom WHERE po_ID=test_po.ID) < (SELECT SUM(quantity) FROM test_po_bom WHERE po_ID=test_po.ID)";
$result = mysql_query($SQL) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo $row['test_po_ID'].'<br>';
}
それは何も吐き出さず、私は多くの異なるバリエーションを試しましたが、私はそれを理解することができません。