Link to home
Create AccountLog in
Avatar of helpchrisplz
helpchrisplz

asked on

php while loop killing my brain power help!

Hi i have a while loop that is outputting correctly when it has no html inside it. but as soon as i add my html inside the loop it only goes round the loop once.

this code outputs varr as 1 2 3 when it is like this:

<?php 

			$db = Loader::db();
			$rs=$db->Execute('SELECT user_name, commentText FROM btGuestBookEntries where approved = 1 ORDER BY RAND()');
			 
			 
			$varr=0;
			while ($varr<=$field_1_select_value):			
			  
			$varr++;
			echo $varr;
			$row = $rs->FetchRow();
			$username=$row['user_name'];
			$commentText=$row['commentText'];
			 			 
			?>
			 
			
			 
			 
			<?php endwhile;?>

Open in new window



this is good that it is being out put as  1 2 3 but as soon as i enter my html the var only outputs 1. so the loop is breaking.

this is with my html:

<?php 

			$db = Loader::db();
			$rs=$db->Execute('SELECT user_name, commentText FROM btGuestBookEntries where approved = 1 ORDER BY RAND()');
			 
			 
			$varr=0;
			while ($varr<=$field_1_select_value):			
			  
			$varr++;
			echo $varr;
			$row = $rs->FetchRow();
			$username=$row['user_name'];
			$commentText=$row['commentText'];
			 			 
			?>
			 
			<div id="allinone_contentSlider_common">
			 
				 <ul class="allinone_contentSlider_list">
				  
					<li data-text-id="#allinone_contentSlider_photoText<?php echo $varr;?>"></li>
				
				 </ul>
			 
			 
				 <div id="allinone_contentSlider_photoText1" class="allinone_contentSlider_texts">
						<div  class="allinone_contentSlider_text_line textElement11_common" data-initial-left="355" data-initial-top="-30" data-final-left="355" data-final-top="45" data-duration="0.5" data-fade-start="0" data-delay="0"><?php echo $username; ?></div>
						<div  class="allinone_contentSlider_text_line textElement12_common" data-initial-left="355" data-initial-top="30" data-final-left="355" data-final-top="115" data-duration="0.5" data-fade-start="0" data-delay="0"><?php echo $commentText; ?></div>
						
				 </div>
				 
				 <div id="allinone_contentSlider_photoText2" class="allinone_contentSlider_texts">
						<div  class="allinone_contentSlider_text_line textElement11_common" data-initial-left="355" data-initial-top="-30" data-final-left="355" data-final-top="45" data-duration="0.5" data-fade-start="0" data-delay="0"><?php echo $username; ?></div>
						<div  class="allinone_contentSlider_text_line textElement12_common" data-initial-left="355" data-initial-top="30" data-final-left="355" data-final-top="115" data-duration="0.5" data-fade-start="0" data-delay="0"><?php echo $commentText; ?></div>
						
				 </div>
			 
			 </div> 
			 
			 
			<?php endwhile;?>

Open in new window




how can i make it not break? thanks.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Where is $field_1_select_value being set?  It's not in that code.  Try echoing it on line 11 along with $varr to see what you have.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of helpchrisplz
helpchrisplz

ASKER

ahh i included all the html in the while when i should have only had parts.

the bits that need to be spit out are the:


 <li>

and the:

<div id="allinone_contentSlider_photoText2" class="allinone_contentSlider_texts">
    <div  class="allinone_contentSlider_text_line textElement11_common" data-initial-left="355" data-initial-top="-30" data-final-left="355" data-final-top="45" data-duration="0.5" data-fade-start="0" data-delay="0">$username</div>
 

each <li> creates one pagination button for the image slider and the divs are the text on each slide.  the divs get connected to each <li> by its ID appended by a number

hmmm i need to rethink how i can output this.
i need like two sets of while loops.

 as the <li> needs to be output with in its <ul> and then the divs need duplicating separately  for each slide.

any one know what i am on about lol ? :O
ok managed to get it to work.

<?php 
					

			$db = Loader::db();
			$rs=$db->Execute('SELECT user_name, commentText FROM btGuestBookEntries where approved = 1 ORDER BY RAND()');
			 
			 
			$out = NULL;
			$TextOut = NULL;
			
$varr=0;
while ($varr < $field_1_select_value)
{
    $varr++;
	
    $row         = $rs->FetchRow();
    $username    = $row['user_name'];
    $commentText = $row['commentText'];
              
    $str = <<<EOD

    <li data-text-id="#allinone_contentSlider_photoText$varr"></li>   
EOD;
	
    $out .= $str;	
	
	$TextStr = <<<EOD

    <div id="allinone_contentSlider_photoText$varr" class="allinone_contentSlider_texts">
		<div  class="allinone_contentSlider_text_line textElement11_common" data-initial-left="355" data-initial-top="-30" data-final-left="355" data-final-top="45" data-duration="0.5" data-fade-start="0" data-delay="0">$username</div>
		<div  class="allinone_contentSlider_text_line textElement12_common" data-initial-left="355" data-initial-top="30" data-final-left="355" data-final-top="115" data-duration="0.5" data-fade-start="0" data-delay="0">$commentText</div>
	</div>   
	
	
EOD;
	
    $TextOut .= $TextStr;	
}
?>
<div id="allinone_contentSlider_common">
					<ul class="allinone_contentSlider_list"> 
					<?php echo $out;?>
					</ul> 
					
					<?php echo $TextOut;?>
					
					
</div>

Open in new window

the <<<EOD helped me thanks