Ne.OnZ Posted July 21, 2008 Share Posted July 21, 2008 Hello, I seem to being a having with this: <?php $sql = "SELECT b_cat.id, b_cat.category, b_top.cat_id, b_top.picture, b_top.forum, b_top.description FROM b_cat, b_top WHERE b_cat.id = b_top.cat_id"; $res = mysql_query($sql) OR die(mysql_error()); while($db = mysql_fetch_array($res)) { echo "<table class='f_board margin'> <div class='f_cat margin'>" . $db['category'] . '</div>'; echo "<tr> <td style='width: 80px'><img src='" . $db['picture']; echo "' alt='' /></td>"; echo "<td style='width: 400px; text-align: left'>" . $db['forum'] . '<p>' . $db['description'] . '</p></td>'; echo "<td style='width: 100px'> Topics: 0<br /> Posts: 0 </td> <td style='width: 203px'> Last Post: Time<br /> Topic Name: Name<br /> By: Username </td> </tr>"; echo "</table>"; } ?> The problem is it displays a new table for every new $db['forum']. The way I wanted is if "b_cat.id == b_top.cat_id" then echo the category name and all the forum names under it. Right now it echoes the same category more then once. It's like this: ------------------- |Category | ------------------- Forum ------------------- |Category | ------------------- Forum ------------------- |Category | ------------------- Forum Should be Like this: ------------------- |Category | ------------------- Forum Forum Forum Only create a table if "b_cat.id == b_top.cat_id" is a different number. Hope that made sense. Any help would be appreciated. Thank You! :) Link to comment https://forums.phpfreaks.com/topic/115757-while-logic/ Share on other sites More sharing options...
ocpaul20 Posted July 21, 2008 Share Posted July 21, 2008 sort it in the sql and check for change of value. print heading on new value. Link to comment https://forums.phpfreaks.com/topic/115757-while-logic/#findComment-595337 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.