Query help while with filters
Posted: Thu Jul 08, 2010 2:06 pm
I am creating a search tool to filter out templates by Product, and/or by category.
I have an empty table(s) so im having a hard time testing my query but am i doing it the efficient way?
when i echo out the query with the post data
The tables are empty so i can not tell if its working or not and will not be able to test it for couple weeks.
Table Structures
templates_products_associated
templates_categories_associated
thanks
I have an empty table(s) so im having a hard time testing my query but am i doing it the efficient way?
Code: Select all
if (isset($_SESSION['template_pub']) || isset($_SESSION['template_cat'])){
$template_query = "SELECT * FROM templates WHERE id=(SELECT templateid FROM templates_products_associated WHERE productid={$_SESSION['template_pub']}) AND id=(SELECT templateid FROM templates_categories_associated WHERE categoryid={$_SESSION['template_cat']})";
}
Code: Select all
SELECT * FROM templates WHERE id=(SELECT templateid FROM templates_products_associated WHERE productid=5) AND id=(SELECT templatedid FROM templates_categories_associated WHERE categoryid=1)Table Structures
templates_products_associated
Code: Select all
templateid | integer | not null
productid | integer | not null
"templates_products_associated_productid_fkey" FOREIGN KEY (productid) REFERENCES pubs(productid)
"templates_products_associated_templateid_fkey" FOREIGN KEY (templateid) REFERENCES templates(id)
Code: Select all
templateid | integer | not null
categoryid | integer | not null
"templates_categories_associated_categoryid_fkey" FOREIGN KEY (categoryid) REFERENCES templates_categories(id)
"templates_categories_associated_templateid_fkey" FOREIGN KEY (templateid) REFERENCES templates(id)