Nieuw lid |
|
cloudstrife schreef: Probeer eens met een outer join.
Bedankt. Hiermee is het gelukt. Kreeg eerst echter een foutmelding met een UNION ALL werkt het dan weer wel.
De code:
SELECT code, product_id, omschrijving, sales_amount, sub, sales_datum,
FROM sales
LEFT OUTER JOIN producten ON sales.product_id = producten.code
WHERE sub = '$idgroep'
UNION ALL
SELECT code, product_id, omschrijving, sales_amount, sub, sales_datum
FROM sales
RIGHT OUTER JOIN producten ON sales.product_id = producten.code
WHERE sales_amount IS NULL
ORDER BY code ASC
SELECT code, product_id, omschrijving, sales_amount, sub, sales_datum, FROM sales LEFT OUTER JOIN producten ON sales.product_id = producten.code WHERE sub = '$idgroep' UNION ALL SELECT code, product_id, omschrijving, sales_amount, sub, sales_datum FROM sales RIGHT OUTER JOIN producten ON sales.product_id = producten.code WHERE sales_amount IS NULL ORDER BY code ASC
Jelmerhollan schreef: Waarom echo je trouwens je hele tabel? Is onnodig en onoverzichtelijk, als je alleen je kleine php stukje in je <?php ?> tags zet, dan wordt het (naar mijn mening overzichtelijker)
Eigenlijk zo aangeleerd in het begin. Vandaar. Is nu een soort van automatisme. Hoewel ik ook wel eens tables buiten de <?php ?> zet maar dat is vrij zeldzaam. Al zie je dan wel wat html is en welke php. En dat is, inderdaad, wel handiger.
Edit:
Ik heb nu alleen een probleem. Ik wil dat alleen de laatste ingevulde waarde wordt getoond. Dus per product. Dat krijg ik nu niet meer voor elkaar. |