Jump to content

count how many posts there are in a forum category


jwk811

Recommended Posts

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

Link to comment
Share on other sites

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'));

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.