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 [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to