Yesterday when I was working on php script I noticed that categories and subcategories works seperatly
if I clicked on main category its show all articles under this main category and nothing imported from subcategories, now am working on somthing like this, so what should I do to avoid this mistake ?
someone told me to use inner join but really I don't get the whole picture of this. I can't imagin how I can use this in my SQL command.
for example
Category with id = 1 has subcategories with parent_id = 1 thier ids are : 15 - 20 - 38
if I specified category 1 in my search it will show all items alson in subcategories .
OsaMasw
13
Loving Helper
Recommended Answers
Jump to PostPost your database schema for the articles, category and sub category tables and the PHP code you already have.
Jump to PostLeft join does that well:
SELECT * FROM `category` `c` LEFT JOIN `sub_category` `sc` ON `c`.`cat_id` = `sc`.`cat_id` WHERE `c`.`cat_id` IN(1,3,8)
you can use group by's to count up how many times a field occurs too
eg. how many subcats each category has
Jump to Postwhen you insert your sub category in database pass the id's of category too.
Jump to Postcan you give us the code how you fatch the category and subcategory from data base.
All 16 Replies
blocblue
238
Posting Pro in Training
Featured Poster
Biiim
182
Junior Poster
OsaMasw
13
Loving Helper
AARTI SHRIVAS
2
Posting Pro in Training
OsaMasw
13
Loving Helper
AARTI SHRIVAS
2
Posting Pro in Training
OsaMasw
13
Loving Helper
AARTI SHRIVAS
2
Posting Pro in Training
OsaMasw
13
Loving Helper
AARTI SHRIVAS
2
Posting Pro in Training
AARTI SHRIVAS
2
Posting Pro in Training
blocblue
238
Posting Pro in Training
Featured Poster
OsaMasw
13
Loving Helper
OsaMasw
13
Loving Helper
blocblue
238
Posting Pro in Training
Featured Poster
OsaMasw
13
Loving Helper
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.