Re: Re: Begging for help!!!! Thank you!!!!

From: Date: Tue, 25 Jul 2000 22:52:06 +0000
Subject: Re: Re: Begging for help!!!! Thank you!!!!
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-1483@lists.php.net to get a copy of this message
**Sent to the list and privately** A many-to-many relationship is typically modelled in three tables. Not one table. Not two tables. Three tables. In your case, it looks like they'd be called something like: product, type, and product_type. product (id, name, ...) type (id, name, ...) product_type (productid, typeid) The SQL to get your list would be something like: SELECT product.name, type.name FROM product, type, product_type WHERE product.id = product_type.productid AND type.id = product_type.typeid If you wanted a specific product, you'd slap on "AND product.name LIKE 'Super Product 2000'" at the end of the where clause. If you wanted all products for a specific type, you'd slap on "AND type.name LIKE 'Intel'" at the end of the where clause. Play around with this model for a bit. I think you'll get the hang of it pretty quickly. HTH, Doug Milk Man was heard at 06:14 PM 7/25/00 EDT to say: > >Please help me! Lots of thanks! > >Milkman. > >>From: "Milk Man" <milkmansql@hotmail.com> >>To: milkmansql@hotmail.com, mysql@lists.mysql.com >>Subject: Beging for help!!!! Thank you!!!! >>Date: Tue, 25 Jul 2000 17:57:00 EDT >> >> >>25 Jul 2000 14:15:26 EDT >>> >>>Dear all, >>> >>>Please tell the newbie here if I am on the right track. I can't move >>>further if I am not sure if I am on the right track. >>> >>>Dear Mr. DuBois, I read your book. It is very clear. But I don't know if >>>the following design is normal/good? Could you please just give it a >>>glance? I show 2 tables, each has 3 fields and 3 records. I think I'm >>>trying to design a many-to-many tables. >>> >>>Thank you!!!! >>> >>>Milkman. >>> >>>>From: "Milk Man" <milkmansql@hotmail.com> >>>>To: mysql@lists.mysql.com >>>>Subject: Table Designs??? >>>>Date: Mon, 24 Jul 2000 18:47:16 EDT >>>> >>>>Hi all, >>>> >>>>I want a table to hold product info. Another table to store product >>>>type. >>>>One type may have many products and one product may have many types. >>>>Here >>>>is a simple data: >>>> >>>>Product Table: >>>>------------- >>>> >>>>prodID typeString Description >>>> >>>>1 AMD, Intel >>>>2 AMD >>>>3 Intel >>>> >>>> >>>>Type Table: >>>>------------ >>>> >>>>index typeName prodID >>>> >>>>1 AMD 1 >>>>2 AMD 2 >>>>3 Intel 1 >>>>4 Intel 3 >>>> >>>>My site has search by categories. I have SELECT * FROM type, product >>>>WHERE >>>>type.typeName = 'AMD' AND type.prodID = product.prodID >>>> >>>>I use the field typeString in the Product table so that when people >>>>search >>>>by keywords, I only search the typeString and Description fields in the >>>>Product table (not the Type Table) and pull out the results. >>>> >>>>Is that the right way to go? >>>>And typeName is indexed (ofcourse product.prodID and type.index are >>>>indexed). >>>> >>>>Thank you very much. >>>> >>>>Milkman.

« previous php.db (#1483) next »