Re: MySQL Query Help
| From: | Simcha Younger | Date: | Sun, 21 Nov 2010 07:37:29 +0000 |
| Subject: | Re: MySQL Query Help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-309593@lists.php.net to get a copy of this message | ||
On Sat, 20 Nov 2010 13:54:29 -0700
"Ben Miller" <biprellim@gmail.com> wrote:
> Hi,
>
> I'm building a website for a client in which I need to compare their
> products, side-by-side, but only include criteria for which all selected
> products have a value for that criteria.
>
> In my database (MySQL), I have a tables named "products","criteria" and
> "criteria_values"
>
> If I have something like
>
> $selected_product = array("1"=>"Product
> 1","2"=>"Product 2"...) // All
> products selected for comparison by the user
>
> I need to get only rows from "criteria" where there is a row in
> "criteria_values" matching "criteria.criteria_id" for each
> $selected_product
> - in other words, if any of the $selected_product does not have a row in
> "criteria_values" that matches "criteria.criteria_id", that criteria would
> not be returned. I hope that makes sense.
It would be a lot easier to think about this if you could provide the table structure or create
table statements.
If I understood correctly, you have products which reference a criteria ID which has no matching
value. If this is the problem you have a to first take care of the integrity of your data, as this
should never happen.
--
Simcha Younger <simcha@syounger.com>