marksie1988 Posted February 28, 2008 Share Posted February 28, 2008 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'); ?> Quote Link to comment Share on other sites More sharing options...
tinker Posted February 28, 2008 Share Posted February 28, 2008 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!) Quote Link to comment Share on other sites More sharing options...
marksie1988 Posted February 29, 2008 Author Share Posted February 29, 2008 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; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.