Post your database schema for the articles, category and sub category tables and the PHP code you already have.
blocblue
Practically a Posting Shark
837 posts since Jan 2008
Reputation Points: 272
Solved Threads: 161
Skill Endorsements: 12
Something like the following should let you find all items in a specified category (including sub categories).
I wasn't sure what your table names were, so I've called them items and categories.
SELECT `i`.*
FROM `items` `i`
INNER JOIN `categories` `c` ON (`c`.`id` = `i`.`item_cat`)
WHERE (`c`.`id` = 1 OR `c`.`parent_id` = 1);
blocblue
Practically a Posting Shark
837 posts since Jan 2008
Reputation Points: 272
Solved Threads: 161
Skill Endorsements: 12
Without seeing your full database schema, it's difficult to know whether this is correct. Also, it's advisable to include the table alias with column names referenced in the query.
$sql = "SELECT `i`.*
FROM `items` `i`
INNER JOIN `categories` `c` ON (`c`.`id` = `i`.`item_cat`)
WHERE (`c`.`id` = {$cat_id} OR `c`.`parent_id` = {$cat_id})
AND `ad_active` = 1
ORDER BY `ad_date`";
blocblue
Practically a Posting Shark
837 posts since Jan 2008
Reputation Points: 272
Solved Threads: 161
Skill Endorsements: 12
Question Answered as of 3 Months Ago by
arti18,
blocblue
and
Biiim