Haveing a while statement inside another while statement

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

Post Reply
User avatar
genetix
Forum Contributor
Posts: 115
Joined: Fri Aug 01, 2003 7:40 pm
Location: Sask, Regina
Contact:

Haveing a while statement inside another while statement

Post by genetix »

For my website I'm making my own forums but I'm trying to make one function do like 60 things at once. I have a while statememt and that echoes the category of the forums. But inside that while statement under where it echeos the catagory I want to add another while statement to echo the forums in that specific category.

I have been fiddling around with it and my browser just kindof "ignores" the second while statement.

Code: Select all

<?php
while($category=mysql_fetch_array($results))
{
$categoryname = $category['name'];
echo "
<table border=1 cellpadding=0 cellspacing=0 width=100%>
<tr><td colspan=4><font size=4><b> $categoryname</b></font></td></tr>

<tr>
<td width=50><center><b> </b></center></td>

<td width=70%><B>Forum:</b></td>

<td><center><b>Posts</b></center></td>

<td><center><b>Recent Posts</b></center></td></tr>";
$fs = mysql_query("SELECT * FROM forums WHERE category='$categoryname'") or die(mysql_error());


while($forum = mysql_fetch_array($fs))
{
$fdate = $forum['date'];
$ftitle = $forum['title'];
$fposter = $forum['poster'];
$fname = $forum['forumn'];
$fdesc = $forum['description'];
echo "
<tr>
<td width=50><center>V/U</center></td>

<td width=70%><B>$fname</b><br><font size=2>$fdesc</font></td>

<td><center><b>$pcount</b></center></td>";

if(!$forum['date']) {
echo "<td><font size=2>No New Posts</font></td></tr>";
}else{
echo "
<td><font size=2>$fdate<br>
In: $ftitle<br>
By: $fposter</font></td></tr>";
}

}
echo "</table><br><br>";
}


?>
markbeadle
Forum Commoner
Posts: 29
Joined: Tue Dec 02, 2003 2:50 am
Location: Aachen, Germany

Post by markbeadle »

Try using mysql_fetch_assoc instead of mysql_fetch array. I believe your $category['name'] is not being set as the return values are numerically indexed. Hence you are not returning any values for the second while.
User avatar
genetix
Forum Contributor
Posts: 115
Joined: Fri Aug 01, 2003 7:40 pm
Location: Sask, Regina
Contact:

Post by genetix »

it works now I just had my database stats wrong.
Post Reply