Clarkeez Posted August 6, 2011 Share Posted August 6, 2011 Hi, Im new to this complicated query methods and I'd like some help to handle the data I get from it. Im played with for, and foreach and such, i just cant get it tow ork see comment in code <?php $q_forums = query("SELECT fa.id AS fa_id, fa.title AS fa_title, fa.parent AS fa_parent, fa.sub AS fa_sub, fb.id AS fb_id, fb.title AS fb_title, fb.descr AS fb_descr FROM forum fa LEFT OUTER JOIN forum fb ON fb.parent = fa.id AND fb.sub = '1' ORDER BY fa.ord, fb.ord"); # Display echo '<table cellpadding="0" cellspacing="0" border="0" <tr><th>Forums</th><th class="center">Topics</th></tr>'; if(!$q_forums) echo '<div class="errorbox">'.mysql_error().'</div>'; endif; # Get Forums while($d_forums = mysql_fetch_array($q_forums)): /* for each of the rows from $d_forums['fa_id'] exists, and the coloumn fa_sub = 0, do this */ echo '<tr><td class="forum_titledescr"> <span class="forum_title" style="font-size:16pt;">'.$d_forums['fa_title'].'</span> </td><td class="forum_topiccount"></td></tr>'; /**/ endwhile; ?> Link to comment https://forums.phpfreaks.com/topic/244041-handling-results-from-query/ Share on other sites More sharing options...
radiations3 Posted August 6, 2011 Share Posted August 6, 2011 KIndly describe your problem more clearly..... Link to comment https://forums.phpfreaks.com/topic/244041-handling-results-from-query/#findComment-1253258 Share on other sites More sharing options...
MasterACE14 Posted August 6, 2011 Share Posted August 6, 2011 I can't see anything wrong with you code. Are you not getting the output you're expecting? If so double check your query is correct. Link to comment https://forums.phpfreaks.com/topic/244041-handling-results-from-query/#findComment-1253272 Share on other sites More sharing options...
Clarkeez Posted August 6, 2011 Author Share Posted August 6, 2011 Ok, I've changed some things here we go. <?php $q_forums = query("SELECT fc.id AS fc_id, fc.title AS fc_title, fc.descr AS fc_descr, fc.sub AS fc_sub, ff.id AS ff_id, ff.title AS ff_title, ff.descr AS ff_descr, ff.sub AS ff_sub, ff.parent AS ff_parent FROM forum fc LEFT OUTER JOIN forum ff ON ff.parent = fc.id "); # Display echo '<table cellpadding="0" cellspacing="0" border="0" <tr><th>Forums</th><th class="center">Topics</th></tr>'; if(!$q_forums): echo '<div class="errorbox">'.mysql_error().'</div>'; endif; # Get Forums while($d_forums = mysql_fetch_array($q_forums)): if($d_forums['fc_sub'] == 0): echo '<tr><td class="forum_titledescr"> <span class="forum_title" style="font-size:16pt;">'.$d_forums['fc_title'].'</span> </td><td class="forum_topiccount"></td></tr>'; while($d_forums['ff_sub'] == 1 && $d_forums['ff_parent'] == $d_forums['fc_id']): echo '<tr class="row"><td class="forum_titledescr"> <a href="forum.php?id='.$d_forums['ff_id'].'"><span class="forum_title" id="spacer">'.$d_forums['ff_title'].'</span><span class="forum_descr"> - '.$d_forums['ff_descr'].'</span></a> </td><td class="forum_topiccount">tobedone</td></tr>'; endwhile; endif; endwhile; ?> Im having a hard time describing what I want it to do, so Ill show you a pic of the output of this It's this part causing the trouble, I THINK <?php while($d_forums['ff_sub'] == 1 && $d_forums['ff_parent'] == $d_forums['fc_id']): echo '<tr class="row"><td class="forum_titledescr"> <a href="forum.php?id='.$d_forums['ff_id'].'"><span class="forum_title" id="spacer">'.$d_forums['ff_title'].'</span><span class="forum_descr"> - '.$d_forums['ff_descr'].'</span></a> </td><td class="forum_topiccount">tobedone</td></tr>'; endwhile; ?> Link to comment https://forums.phpfreaks.com/topic/244041-handling-results-from-query/#findComment-1253283 Share on other sites More sharing options...
MasterACE14 Posted August 6, 2011 Share Posted August 6, 2011 try changing the 'while' to an 'if' like so... <?php if($d_forums['ff_sub'] == 1 && $d_forums['ff_parent'] == $d_forums['fc_id']): echo '<tr class="row"><td class="forum_titledescr"> <a href="forum.php?id='.$d_forums['ff_id'].'"><span class="forum_title" id="spacer">'.$d_forums['ff_title'].'</span><span class="forum_descr"> - '.$d_forums['ff_descr'].'</span></a> </td><td class="forum_topiccount">tobedone</td></tr>'; endif; ?> Link to comment https://forums.phpfreaks.com/topic/244041-handling-results-from-query/#findComment-1253285 Share on other sites More sharing options...
Clarkeez Posted August 6, 2011 Author Share Posted August 6, 2011 Hi, thanks for you reply. Then, this happen :S ? Blog & The Blah Bar should be under General and Rated BG and Arena should be under PvP Link to comment https://forums.phpfreaks.com/topic/244041-handling-results-from-query/#findComment-1253287 Share on other sites More sharing options...
Clarkeez Posted August 6, 2011 Author Share Posted August 6, 2011 See my edit Link to comment https://forums.phpfreaks.com/topic/244041-handling-results-from-query/#findComment-1253289 Share on other sites More sharing options...
MasterACE14 Posted August 6, 2011 Share Posted August 6, 2011 try getting rid of this and see what happens... $d_forums['ff_sub'] == 1 Link to comment https://forums.phpfreaks.com/topic/244041-handling-results-from-query/#findComment-1253291 Share on other sites More sharing options...
Clarkeez Posted August 6, 2011 Author Share Posted August 6, 2011 No difference in the output Shouldn't I need some sort of foreach loop or something Link to comment https://forums.phpfreaks.com/topic/244041-handling-results-from-query/#findComment-1253292 Share on other sites More sharing options...
Clarkeez Posted August 6, 2011 Author Share Posted August 6, 2011 It's meant to look like this.. I cant figure this damn thing out Link to comment https://forums.phpfreaks.com/topic/244041-handling-results-from-query/#findComment-1253339 Share on other sites More sharing options...
kickstart Posted August 6, 2011 Share Posted August 6, 2011 Hi The problem seems to be that you have an inner loop which doesn't change anything, just keeps checking the same variables. Hence probably an endless loop. What you need to do is store the previous titles (probably just the identity of them), and then only output the titles when the new ones are different to the previous ones. All the best Keith Link to comment https://forums.phpfreaks.com/topic/244041-handling-results-from-query/#findComment-1253342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.