jwk811 Posted March 25, 2010 Share Posted March 25, 2010 theres a table called forum_posts and another called forum_category can i select all posts that are in forum_category but only the categories in the parent category $sql = "SELECT cat_id FROM forum_category WHERE cat_parent_id = '$cat_parent_id'"; $result = dbQuery($sql); then select all post from each of those category and add them up. is there an easier way to do this whole category thing its driving me crazy, thanks Quote Link to comment Share on other sites More sharing options...
schilly Posted March 25, 2010 Share Posted March 25, 2010 well it depends what the category identifier is like in the forum_posts table but i think you want something like this: $num_posts = mysql_results(mysql_query("SELECT count(forum_posts.id) FROM forum_posts, forum_category WHERE forum_post.category_id = forum_category.cat_id AND cat_parent_id = '$cat_parent_id')); Quote Link to comment Share on other sites More sharing options...
jwk811 Posted March 29, 2010 Author Share Posted March 29, 2010 why isnt this working for me. any other ways? i fixed the spelling errors but still doesnt work. one bcuz the parent id isnt a column in the posts. i just wanna change the way this all works. help please Quote Link to comment Share on other sites More sharing options...
schilly Posted March 29, 2010 Share Posted March 29, 2010 well start with this: $results = mysql_query("SELECT count(forum_posts.id) FROM forum_posts, forum_category WHERE forum_post.category_id = forum_category.cat_id AND cat_parent_id = '$cat_parent_id') or die(mysql_error()); $num_posts = mysql_result($results); This forum_post.category_id = forum_category.cat_id joins forum_posts and forum_category. make sure the fields are whatever their common column is. This: cat_parent_id = '$cat_parent_id' is from your query in your first post so i assume forum_category has this field in it so the results will be filtered based on Sorry there was an error in my post. mysql_results is mysql_result. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.