Jump to content

Whats going wrong?


twsowerby

Recommended Posts

Hi guys ive got a forum under construction and this is the main "forum view" page. I'm trying to get it so that it will count the posts and topics in each forum category and I'm almost there I think. Unfortunately instead of counting the number of posts and topics in each category and displaying the totals next to the relevant category, it is totalling all of the posts and topics in the entire forum and ouputting the total next to the top category.

 

The code for the page is below:

 

<?php 

// File: index.php
//
define('IN_FORUM', true);
include_once "includes/functions.php";
include "includes/header.php";

echo	"<table class='maintable'>";

echo	"<tr class='headline'>
	<td class='title1'>Film Genres</td>
	<td class='title2' colspan=2><a href='unanswered.php'>View Unanswered Posts</td>
	</tr>";

$getcat="select forum_genres.genre_id as id, genre_title, genre_desc, genre_mod
	from forum_genres
	left join forum_posts
	on forum_genres.genre_id = forum_posts.genre_id
	and forum_posts.postid = 0 
	group by id;";

$getcat2=mysql_query($getcat) or die("Could not get categories");

if (mysql_num_rows($getcat2) == 0) {
echo " <br>\n";
echo " There are currently no categories in the forum.\n";
}

while($row=mysql_fetch_array($getcat2)) {
$getlast="select * from forum_posts where genre_id = $row[id] order by realtime limit 1";
$getlast=mysql_query($getlast) or die("Could not get categories");

while($row1=mysql_fetch_array($getlast)) {
$getLastid = $row1['postid'];
$getLasttitle = $row1['title'];
$getLastposter = $row1['lastposter'];
$getLasttime = $row1['showtime'];
}

$getposts="select count(postid) as countPost from forum_posts where genre_id = $row[id]";
$getposts2=mysql_query($getposts) or die("Could not get categories");

while($rowC=mysql_fetch_array($getposts2)){
$postcount = $rowC['countPost'];
}

$gettopics="select count(postid) as countTopics from forum_posts where genre_id = $row[id] and parentid = 0";
$gettopics2=mysql_query($gettopics) or die("Could not get categories");

while($rowD=mysql_fetch_array($gettopics2)){
$topiccount = $rowD['countTopics'];
}

echo "<tr class='mainrow'>";
echo  "<td class='genrerowTitle'><a href='thread_view.php?id=$row[id]'>$row[genre_title]</a><br />$row[genre_desc]</td>";
echo  "<td class='genrerowPosts'>posts ".$postcount."<br />topics ".$topiccount."</td>";
echo  "<td class='genrerowStats'>Last post by: ".$getLastposter."<br/>in <a href='message.php?id=$getLastid'>".
$getLasttitle."</a><br/>on ".$getLasttime."</td>";
echo	"</tr>";

}

include "includes/footer.php";

?>

 

I really cant figure this out, my php knowledge is still lacking a bit. Any help would be great, thanks!

 

Tom

Link to comment
https://forums.phpfreaks.com/topic/81910-whats-going-wrong/
Share on other sites

ok

 

assuming that ALL your posts are in teh one table:

 

SELECT post_ID from POSTS

 

myslqi_nom_rows($QUERY_VARIABLE);

 

as for the topics.... do the same thing but with a WHERE added to the query

 

SELECT topic from POSTS WHERE topic == "XXX"

 

gdlk

Link to comment
https://forums.phpfreaks.com/topic/81910-whats-going-wrong/#findComment-416169
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.