MySql select column names

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Hi there, I am working with the following table:
SQL Code: [ Select ]
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;
  1. CREATE TABLE `user`(
  2. `id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  3. `name` VARCHAR(30) NOT NULL,
  4. `country` VARCHAR(100) NOT NULL,
  5. `general_newsletter` CHAR(1) NOT NULL,
  6. `sports_newsletter` CHAR(1) NOT NULL
  7. )ENGINE=MyISAM;


Let's say I have the following data in the table:
SQL Code: [ Select ]
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');
  1. INSERT INTO `user` VALUES(NULL,'RT','SA','1','0');
  2. INSERT INTO `user` VALUES(NULL,'Joe','US','0','1');
  3. 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?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • RedBMedia
  • Proficient
  • Proficient
  • User avatar
  • Posts: 315

Post 3+ Months Ago

I had a simular issue recently, and I had to write a series of IF statements. It wasn't very clean, but it worked.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 73 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.