RE: [PHP] mysql question
| From: | John W. Holmes | Date: | Sun, 20 Oct 2002 17:58:48 +0000 |
| Subject: | RE: [PHP] mysql question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-120677@lists.php.net to get a copy of this message | ||
> I have some images in my database, and they are put
> into certain categories. So what i have in my
> database is a table called images and a table called
> categories. My question is I want to retrieve images
> by selected categories the user chooses. So if there
> are a total of five categories, the user chooses two
> categories to views images, it will select those
> images only by the two categories the user selected.
> How can I do this with just submitting one query
> instead of submitting two queries? In both the image
> table and category table there is a unique id. So the
> image in the image table can reference the category in
> the category table.
SELECT i.* FROM images i, categories c WHERE i.category_id =
c.category_id AND c.category_id IN (2,3,4)
Where 2,3,4 are the categories the user chose. You can use PHP to insert
those numbers into your query...
---John Holmes...