Jump to content

Recommended Posts

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

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

f7ec4b5c.png

 

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;
?>

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;
?>

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.