I would suggest a reorganization of your database tables.  The best way I
know of to structure your items/subcategories/categories is to create 4
tables instead of 3.

Your tables for 'categories' and 'subcategories' tables could stay the
same.  However you'd need to remove the CAT and SUB columns from your
'products' table, and create a new table to store those values in.

The items you gave:

>
> ID   CAT    SUB    NAME    DESCRIPTION
> --------------------------------------
> 1    1,4    23,32  Foo     Blah blah blah
> 2    1      7,21   Bar     Blah blee bloo
>
>
Could then be represented as follows in the fourth table:
categorized_items
+--------+--------+-----------+
|item_id | cat_id | subcat_id |
+--------+--------+-----------+
|      1 |      1 |        23 |
|      1 |      4 |        32 |
|      2 |      1 |         7 |
|      2 |      1 |        21 |
+--------+--------+-----------+

Then to select all items in category 1 and subcategory 23, your query would
be :
(assuming $cat and $sub have been extracted from $_GET)
"
SELECT * FROM categorized_items, products
WHERE categorized_items.cat_id=$cat
AND categorized_items.subcat_id=$sub
AND products.id=categorized_items.item_id
"


I believe (not sure) this method is faster since it's searching integers
only.  It may seem messier with the extra table, but from what I've read,
it's a much more efficient way to query  categorized items.


--

  katy
  ~~+++~~                         +
       no matter where you go,
           there you are
  +                         ~~+++~~


[Non-text portions of this message have been removed]



Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to