Add
Code:
GROUP BY p.productid
after
to make it look like
Code:
p.forsale="Y" GROUP BY p.productid
Basically put it where the LIMIT BY was.
i.e.
Code:
$query = '
SELECT
p.productid,
p.product,
pc.categoryid
FROM
' . $sql_tbl['products'] . ' p
INNER JOIN ' . $sql_tbl['products_categories'] . ' pc ON (p.productid = pc.productid)
WHERE
p.forsale="Y" GROUP BY p.productid
';