Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How would I exclude certain categories within my query?

    Thanks for any help with this.

    My client has a cart for which I've made a custom homepage.

    We use this query to display the 3 newest items on the homepage:

    Code:
    $query = 'SELECT * FROM `tbl_item` GROUP BY `item_id` ORDER BY `item_id` DESC LIMIT 3';
    Now, my client has several categories which he does not want the items of to be displayed on the homepage.

    In the database the column is "category_id" which is within the same table as in the query shown above.

    How would I exclude several categories from being displayed via the query above? Thanks.

    edit: I found this code will exclude 1 ID, but I need to exclude multiple ID's, not sure how.

    Code:
    $query = 'SELECT * FROM `tbl_item` WHERE NOT (category_id = "138") GROUP BY `item_id` ORDER BY `item_id` DESC LIMIT 3';
    Ideally, I would like to exclude a whole parent ID, so I just have to put one ID in the query, but the parent_id is in another table, the "categories" table, not the items table.

    I believe I have to do a subselect, but I don't know how.

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    where category not in (x,y,z)
    would exclude those categories.

  • #3
    New Coder
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, that did it!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •