Jump to content

[SOLVED] PHP Forum repeats the boards?


marksie1988

Recommended Posts

Hi,

 

i have created a forum as i dont want all of the functionality that smf etc has on it i wanted it to be very basic and simple.

 

what is happening is that the code seems to run the while statment 3 times this is what it is showing

 

forumissue.bmp

 

here is my code may be something very simple that im just missing

 

<?php 
include("../login/include/session.php");
include("../inc/header.php");
include("../inc/bbcode.php"); 
?>
    <h2>Forum</h2>
<?php 

$cat="SELECT * FROM forum_boards,forum_category";//select the info from the category table
$cat2=mysql_query($cat) or die("Could not get threads");
$color1 = "#000000"; 
$color2 = "#999999";  
$row_count = 0; 

  while($cat3=mysql_fetch_array($cat2)) {
  
        $cat1=$cat3['category'];
        
	//display the category as a header
        print "<table class='maintable'>";
	print "<h3>$cat1</h3>";

       $getthreads="SELECT * from forum_boards WHERE category = '$cat1'";//select the boards from the table
       $getthreads2=mysql_query($getthreads) or die("Could not get threads123");
   
       while($getthreads3=mysql_fetch_array($getthreads2)){

		$getthreads3[title]=strip_tags($getthreads3[title]);
		$boardid=strip_tags($getthreads3[boardid]);

		$totaltopics = mysql_num_rows(mysql_query("SELECT * FROM forum_posts WHERE boardid='$boardid' AND parentid='0'"));
		$totalposts = mysql_num_rows(mysql_query("SELECT * FROM forum_posts WHERE boardid='$boardid'"));

		$row_color = ($row_count % 2) ? $color1 : $color2;

			 print "<tr class='mainrow' bgcolor='$row_color'><td width='40%' ><A href='boards.php?bid=$getthreads3[boardid]'>$getthreads3[title]</a></td><td>Topics: $totaltopics<br /> Posts: $totalposts</td></tr>";//display the boards
		$row_count++;

  }
}
print "</table>";

include('../inc/footer.php'); 
?>

Link to comment
Share on other sites

I'd suggest going to the mysql manual and use some kind of 'join' and then also add in the group aggregate function 'count', this way you'd be able to achieve all of that in a single mysql call, not recursively as you have here! (I'm only here for a short while today otherwise i'd ask to see your tables, but once you've looked at the manual you'll be able to figure it out!)... groups, join (the join page isn't right, but it does give some examples!)

Link to comment
Share on other sites

dont suppose anyone has an example of what i would do i dont quite understand how to do the above

 

would i use something similar to this? if i changed this to fit my tables it should group by the category?

 

SELECT student.student_name,COUNT(*)

    ->        FROM student,course

    ->        WHERE student.student_id=course.student_id

    ->        GROUP BY student_name;

 

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.