Re: [OT-ish] Optional Extras.

From: Date: Wed, 27 Jun 2001 05:41:37 +0000
Subject: Re: [OT-ish] Optional Extras.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-55335@lists.php.net to get a copy of this message
How about solving both problems at once? :-) Yes, go with the N:N (the technical term for that car_option table) relation, *AND* give yourself a weighted search engine to boot! create table car (car_id auto_increment...); create table option (option_id auto_increment...); create table car_option(car_id int4, option_id int4, key(option_id)); insert into car(name) values('Chevy Nova'); insert into car(name) values('Lexus'); insert into option(name) values('a/c'); insert into option(name) values('power window'); insert into option(name) values('power locks'); insert into car_option(car_id, option_id) values(1, 1); insert into car_option(car_id, option_id) values(2, 1); insert into car_option(car_id, option_id) values(2, 2); insert into car_option(car_id, option_id) values(2, 3); NOTE: The Lexus has all those options (at that price it had better!) and the Nova, well... It has a/c! :-) Now, assume the user wants everything, so you have: $options[1] $options[2] $options[3] all "set" to some value by your checkbox. #Untested code. $query = "select count(car_id), car.name from car, car_option "; $query .= " where car.car_id = car_option.car_id " $query .= " and (1 = 0"; # 1 = 0 is a "starter yeast" for the following: while (list($option_id) = each($options)){ $query .= " or option_id = $option_id "; } # finish off our options OR list... $query .= ")"; $query .= " group by car_id "; -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#55335) next »