Re: [OT-ish] Optional Extras.

From: Date: Wed, 27 Jun 2001 18:37:19 +0000
Subject: Re: [OT-ish] Optional Extras.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-55429@lists.php.net to get a copy of this message
I don't see how this is weighted. I would suggest doing it the easy way and treating the options as keywords and just putting them all in a text field with a fulltext index. this will give you the weighting you want and it will be a lot easier to deal with, but you will have to watch out for things like 'power locks' partially matching 'power doors' (just take out the spaces I guess) On Wed, 27 Jun 2001 00:41:37 -0500, Richard Lynch (ceo@l-i-e.com) wrote: >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 > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >For additional commands, e-mail: php-general-help@lists.php.net >To contact the list administrators, e-mail: php-list- >admin@lists.php.net

« previous php.general (#55429) next »