Best Way to Mix 2 Different Query Results
Posted: Wed Aug 22, 2007 5:14 pm
i'm making a webpage that's going to have dynamic lists. let's say in my database there are two tables, one called "products" and one called "product_categories".
products has these fields:
product_id
product_price
product_title
product_description
product_category_id
and product_categories has the following fields:
product_category_id
product_category_name
i need to use the product_category_id in the products table to reference the product_category_name in the product_categories table so the category names can be used as headers for the products they've been assigned to (via the category id).
so a simplified version of my list would look like this:
<h2>{product_category_name}<h2>
<h5>product_title</h5>
<h5>product_title</h5>
<h5>product_title</h5>
<h2>{another product_category_name}</h2>
<h5>product_title</h5>
<h5>product_title</h5>
<h5>product_title</h5>
<h5>product_title</h5>
<h5>product_title</h5>
<h5>product_title</h5>
and so on.
i can't figure out what to do with the code. i obviously need some kind of complicated loop (or so i think) or some brilliant SQL that i don't know about.
sorry if this is hard to understand, i tried to make it as clear as possible. thanks in advance for any help, it's much appreciated.
products has these fields:
product_id
product_price
product_title
product_description
product_category_id
and product_categories has the following fields:
product_category_id
product_category_name
i need to use the product_category_id in the products table to reference the product_category_name in the product_categories table so the category names can be used as headers for the products they've been assigned to (via the category id).
so a simplified version of my list would look like this:
<h2>{product_category_name}<h2>
<h5>product_title</h5>
<h5>product_title</h5>
<h5>product_title</h5>
<h2>{another product_category_name}</h2>
<h5>product_title</h5>
<h5>product_title</h5>
<h5>product_title</h5>
<h5>product_title</h5>
<h5>product_title</h5>
<h5>product_title</h5>
and so on.
i can't figure out what to do with the code. i obviously need some kind of complicated loop (or so i think) or some brilliant SQL that i don't know about.
sorry if this is hard to understand, i tried to make it as clear as possible. thanks in advance for any help, it's much appreciated.