Jump to content

for each error?


justinwhite

Recommended Posts

Hello, I am just trying to get "forums" to go into "categorys." Look what it does: http://jforum.mine.nu/

 

Here is the code:

 

<?php
include 'connect.php';

//Get forum categories
$query = "SELECT * FROM forum_categories ORDER BY id ASC";
$result = mysql_query($query);
while($categories = mysql_fetch_array($result)){ // Start looping categories
echo '<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">';
foreach($categories as $cat) {

echo '<tr><td width="6%" align="center" bgcolor="#E6E6E6" colspan="5"><strong>';
echo $categories['category'];
echo '</strong></td></tr>';
echo '
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Forum Name </strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Threads</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Posts</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Last Activity </strong></td>
</tr>
';


$forumquery = "SELECT * FROM forum_forums WHERE cat_id=".$categories['id']." ORDER BY id ASC";
$forumresult = mysql_query($forumquery);
while($forums = mysql_fetch_array($forumresult)){

foreach($forums as $forum) {

echo '
<tr>
<td bgcolor="#FFFFFF">'.$forums['id'].'</td>
<td bgcolor="#FFFFFF">'.$forums['name'].'<br /> '.$forums['description'].'<BR></td>
<td align="center" bgcolor="#FFFFFF">'.$forums['threads'].'</td>
<td align="center" bgcolor="#FFFFFF">'.$forums['replies'].'</td>
<td align="center" bgcolor="#FFFFFF">'.$forums['last_activity'].'</td>
</tr>';

		}
	}
}
}
echo '<tr> <td colspan="5" align="right" bgcolor="#E6E6E6">--</td> </tr>';
echo '<br /><br />';	
echo '</table>';

?>

 

 

Can someone please help? Heres what I have in the database

 

forum_categories contains > id, and category

 

forum_forums contains > id, cat_id(for telling which category the forum should go into), name, description, threads, replies, and last activity.

 

Thanks for your help :)

Link to comment
https://forums.phpfreaks.com/topic/99893-for-each-error/
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.