Hi there, I am working with the following table:
CREATE TABLE `user`(
`id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(30) NOT NULL,
`country` VARCHAR(100) NOT NULL,
`general_newsletter` CHAR(1) NOT NULL,
`sports_newsletter` CHAR(1) NOT NULL
)ENGINE=MyISAM;
- CREATE TABLE `user`(
- `id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
- `name` VARCHAR(30) NOT NULL,
- `country` VARCHAR(100) NOT NULL,
- `general_newsletter` CHAR(1) NOT NULL,
- `sports_newsletter` CHAR(1) NOT NULL
- )ENGINE=MyISAM;
Let's say I have the following data in the table:
INSERT INTO `user` VALUES(NULL,'RT','SA','1','0');
INSERT INTO `user` VALUES(NULL,'Joe','US','0','1');
INSERT INTO `user` VALUES(NULL,'Bob','UK','1','1');
- INSERT INTO `user` VALUES(NULL,'RT','SA','1','0');
- INSERT INTO `user` VALUES(NULL,'Joe','US','0','1');
- INSERT INTO `user` VALUES(NULL,'Bob','UK','1','1');
I am building a filter which consists of a bunch of dropdowns (name,country,newsletter) which automatically get populated as the other dropdowns change with ajax. So let's say I select RT from the 'name' dropdown, then 'country' will only contain 'SA' (SELECT DISTINCT(`country`) FROM `user` WHERE `name`='RT'). But what I want to know is, how can I automatically populate the newsletter dropdown with a mysql query.
For instance, when I select 'RT' as the `name`, then `newsletter` will only contain 'general_newsletter', but if I select 'Bob' as the `name` then `newsletter` will contain 'general_newsletter' AND 'sports_newsletter'. Is there a way for me to do this in a single query?
Let's leave all our *plum* where it is and go live in the jungle ...