problem in posts category
i ne开发者_开发知识库ed help in sql query
i have table named -- threads
contain
post_id / post_title .....
and i have categories table named
thread_categories
contain
cate_id / post_id
file.php?cate_id=20
i want get all posts in category id = 20
Thank you
I think it's better to store your categories which is related to threads in a separate table. Otherwise your query will very slow and inefficient.
You can use current table structure and try to use the following query but I don't like it:
SELECT * FROM posts
WHERE FIND_IN_SET(provided_cat_id,REPLACE(thread_categories, '::', ','));
New query:
SELECT * FROM threads t inner join thread_categories tc on t.post_id=tc.post_id
where tc.cate_id=20;
Select * from posts where YourCategoryID in (splitstring('::', thread_categories))
I hope this helps
精彩评论