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 PostSomething 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
andcategories
.SELECT `i`.* FROM `items` `i` INNER JOIN `categories` `c` ON (`c`.`id` = `i`.`item_cat`) …
Jump to PostWithout 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` = …
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.