join / mysql
Maa
- datenbank
0 Maa
Guten Morgen,
es sollen die jeweils aktuellsten Produkte aus einer mySQL DB geholt werden. Mit Bild! Der holt aber zig mal dasselbe Produkt. :(
QUERY:
$res =& $db->query("
SELECT p.name, pic.picture, pi.d_produktbeschreibung
FROM products AS p, productinfo AS pi
LEFT JOIN lnk_product_pic AS lpp ON (p.pid = lpp.pid)
LEFT JOIN picture AS pic ON (lpp.id_picture = pic.id_pic)
WHERE (p.since = '".date('Y')."') OR (p.since = '".(date('Y')-1)."')
AND (p.pid = pi.pid)
ORDER BY p.since DESC");
Tabellenstruktur:
Ach du wolltest die Tabellenstruktur haben ?
Tabelle products
----------------------------------
pid | category | name |since
Tabelle productinfo
----------------------------------
lang | pid | d_produktbeschreibung
Tabelle picture
----------------------------------
id_pic | picture
Tabelle lnk_product_pic
----------------------------------
pid |id_picture
Mittlerweile bin ich so weit:
SELECT p1.name, p3.picture, p4.d_produktbeschreibung
FROM (products p1
INNER JOIN lnk_product_pic p2 on p1.pid = p2.pid
INNER JOIN picture p3 on p3.id_pic = p2.id_picture)
INNER JOIN productinfo p4 on p1.pid = p4.pid
WHERE p1.since between year(curdate())-1 and year(curdate())
AND lang = '".$language."'");
Aber es gibt zu jedem Produkt mehrere Bilder.
Nun wird ein Datensatz jeweils so oft ausgegeben, wie es Bilder für das Produkt gibt. Jeweils mit einem anderen Bild.