Jump to content

[SOLVED] How would I exclude certain categories within my query?


Colleen78

Recommended Posts

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:

$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. :)

Link to comment
Share on other sites

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

$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, but the parent_id is in another table, the "categories" table, not the items table.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.