Advanced Query help!

admin

Administrator
Staff member
I have 3 tables (one for products, one for brand names, and one for prices). I wish to display a list of products with their brand and price. I havent done multiple table queries before, so i'm not quite sure how they go.. (brands table contains brand_id and brand_name, prices table contains product_id and amount, the rest are in products)

My query is as follows:
<.start--->

SELECT product_id, parent_id, product_name, reference_id, brand_id, brand_name, short_description, image_small, amount

FROM products, brands, prices

WHERE prices.product_id=products.product_id AND brands.brand_id=products.brand_id

ORDER BY product_name ASC

<.end--->

I then use the following piece of code to execute the query and check if there are any results.

<.start--->
$result = mysql_query($query,$db);
$numrows = mysql_num_rows($result);
if ($numrows > 0) {
while($row = mysql_fetch_array($result)) {
// DISPLAY ROW
}
}
else { // NO RESULTS }
<.end--->

However, I am getting no results from the query and also getting a "Warning: 0 is not a MySQL result index" on the mysql_num_rows query (which i didnt think was possible)..

Can someone PLEASE help me to fix up my query and also my code???

Jamie
 
Back
Top