Search code examples
phpsqlmysqlcodeigniterwhere-in

CodeIgniter query WHERE column value is one of several qualifying values


I am trying to select categories with certain id's and the sql query is acting really weird, take a look:

SELECT * FROM (`feeds`) WHERE  `cat_id` =1 OR 2 OR 3 LIMIT 0 , 30

The result includes an item with the cat_id of 4, see this picture:

see here

The script does this: a user specifies a country, the script gets all categories with that country id, then the script has to select all feeds with those category ids. The final part is to grab posts with all the feed ids from the previous parts. This is like a news site, the feeds are RSS feeds that get imported. I'm using CodeIgniter for this.


Solution

  • try this:

    SELECT * FROM `feeds`
    WHERE  `cat_id` in (1 ,2 , 3)
    LIMIT 0 , 30
    

    you cannot give

    `cat_id` =1 OR 2 OR 3 
    

    it should be either

    `cat_id` =1 OR `cat_id` =2 OR `cat_id` =3 
    

    or

    `cat_id` in (1,2,3)