PHP Forum repeats the boards?

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

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

First thing you should know is that mysql_fetch_array() returns the result set’s record twice (once as an associated array, once as a numbered array). I don’t know where the third iteration comes from, but your code looks quite messy if you ask me (no offence). But try using mysql_fetch_assoc() instead of mysql_fetch_array and see if that changes anything.

Sponsor our Newsletter | Privacy Policy | Terms of Service