Forum Count help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Smackie wrote:ok im back i figured out it but still not returning what i need its returning as both posts as 0 here is what i got now
Then you need to rethink your queries. They are supposed to make sense.

$get_num_topics... Is that query supposed to get a count of all of the topics? Then why are you counting the forumids where they all have a specific id? What would you think that could possibly do?

And $get_num_posts... That's supposed to give you a count of all posts to a question? Then why are you counting the question_ids where they all have a common a_id, which I assume is the answer's id?

Seriously... The syntax isn't gibberish. COUNT means count. Whatever you put into it will be counted. WHERE means where. Whatever conditions you put in it are the condition that must be met for a row to be counted.

Think about it.
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

No they ain't suppose to get all the topics and all the posts.. here is a picture of my forum to give you an example of what im talking about..


Image

see in each category (test and test2) i want to know how many topics and how many posts are in each one thats what im trying to do..
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

ok i got the topics posting right which is good but the posts isn't working right :?: so i was wondering could i join 2 tables together for this? or how should i do this so the posts count as well


here is what the script looks like

Code: Select all

<?php 

	$id = $_GET['id'];

	$get_topic = mysql_query("SELECT id, heading, description FROM header ORDER BY id DESC") or die(mysql_error());	
		while($topic_info = mysql_fetch_array($get_topic)) {
			$id = $topic_info['id'];
			$heading = stripslashes($topic_info['heading']);
			$description = $topic_info['description'];
	
	$get_num_topics = mysql_query("SELECT forumid FROM forum_question WHERE forumid = $id");
    $topics = mysql_num_rows($get_num_topics);

    $get_num_posts = mysql_query("SELECT question_id FROM forum_answer WHERE question_id = $id");
	$posts = mysql_num_rows($get_num_posts);
?>
on the posts it the id needs to be the id from forum_question db not the header db
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Either you still don't understand what I said to you in my last post, or your table names make absolutely no sense.

Look at your queries...

"SELECT forumid FROM forum_question..."
"SELECT question_id FROM forum_answer..."

Sensibly, forum_question would be each topic, and the forumid of each topic would be the forum that they belong to. Why would $get_num_topics care about the amount of forumids in forum question? You use the same backwards logic in the second query.

SELECT means select. Whatever you put after it, it selects. FROM means from. Whatever you put after it is the table you select from. The reason your code isn't working is because you are writing it wrong.
Post Reply