Multiple Categories - how do you do it?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Multiple Categories - how do you do it?

Post by simonmlewis »

Code: Select all

$query = ("SELECT * FROM products WHERE catid = :c AND (producttype_lightweight = 'yes' OR producttype_backlit = 'yes' OR producttype_traditional = 'yes') LIMIT $offset, $rowsPerPage");
I need to be able to assign each product to one that one top level product type, of three.

These are never changed, so I am choosing it to be static fields rather than dynamically named.
But when it comes to the category page, if they choose Lightweight as the top level, and then Marble as the second level, I want it to only show those where the category ID is for marble (easy) and producttype_lightweight is 'yes'.

But on the same set of code, if they chose Marble and producttype_traditional is 'yes', I want only products to show for that.

With the code above, it's showing me products that are in marble, but also in both lightweight and traditional. It's clear to see why, but I don't see another way around it.

There will be times when a product is in BOTH those top levels, or even three levels. But if they go to Traditional > Marble, I want it to only show those there the catid is for marble, and the traditional is a yes.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Multiple Categories - how do you do it?

Post by requinix »

simonmlewis wrote:With the code above, it's showing me products that are in marble, but also in both lightweight and traditional. It's clear to see why, but I don't see another way around it.
I'm not sure how you're coming up with that query. They can only choose one top-level category, right? So you should never be doing a =yes for more than one at a time.
Post Reply