Jump to content

[SOLVED] Loop Help


Sleeper

Recommended Posts

How could I take the folowing code and cause it to loop the entire section up to said number of time? There are fields such as

$t1

$t1a

a1

$a1

a1fc

 

that would have to chagne to 2's insteas of ones on each a thru g.

 

								<tr>
									<td width="65" align="center" height="40" bgcolor="#CCCCCC">
<font class="time"><?php echo $t1 ?></font><br><font class="time"><?php echo $t1a ?></font></td>
									<td bgcolor="#CCCCCC" align="center" width="94">
												<div align="center">
													<table border="0" cellpadding="0" cellspacing="0" width="100%">
														<tr>
															<td>
															<p align="center">
<select size="1" onchange="fcs()" name="a1" >
<option selected value="<?php echo $a1 ?>"><?php echo $a1 ?></option>
<option>----------</option>
<?php
for ( $counter = 1; $counter <= $number; $counter += 1) {
   echo "<option value=\"$djname[$counter]\">$djname[$counter]</option>
   ";
}
?>
</select></td></tr><tr><td><input type="hidden" name="a1fc" value="" ></td></tr></table></div></td>
<td bgcolor="#CCCCCC" align="center" width="93">

<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><p align="center">
<select size="1" onchange="fcs()" name="b1">
<option selected value="<?php echo $b1 ?>"><?php echo $b1 ?></option>
<option>----------</option>
<?php
for ( $counter = 1; $counter <= $number; $counter += 1) {
   echo "<option value=\"$djname[$counter]\">$djname[$counter]</option>
   ";
}
?></select></td></tr><tr><td>
<input type="hidden" name="b1fc" value="" ></td>
</tr></table></td>
									<td bgcolor="#CCCCCC" align="center" width="95">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><p align="center">
<select size="1" onchange="fcs()" name="c1">
<option selected value="<?php echo $c1 ?>"><?php echo $c1 ?></option>
<option>----------</option>
<?php
for ( $counter = 1; $counter <= $number; $counter += 1) {
   echo "<option value=\"$djname[$counter]\">$djname[$counter]</option>
   ";
}
?></select></td></tr><tr><td><p align="center">
<input type="hidden" name="c1fc" value="" ></td>
<input type="hidden" name="c1v" value="<?php echo $c1 ?>" >

</tr></table>
</td>
									<td bgcolor="#CCCCCC" align="center" width="95">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><p align="center">
<select size="1" onchange="fcs()" name="d1">
<option selected value="<?php echo $d1 ?>"><?php echo $d1 ?></option>
<option>----------</option>
<?php
for ( $counter = 1; $counter <= $number; $counter += 1) {
   echo "<option value=\"$djname[$counter]\">$djname[$counter]</option>
   ";
}
?></select></td></tr><tr><td><p align="center">
<input type="hidden" name="d1fc" value="" ></td>
<input type="hidden" name="d1v" value="<?php echo $d1 ?>" >

</tr></table></td>
									<td bgcolor="#CCCCCC" align="center" width="95">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><p align="center">
<select size="1" onchange="fcs()" name="e1">
<option selected value="<?php echo $e1 ?>"><?php echo $e1 ?></option>
<option>----------</option>
<?php
for ( $counter = 1; $counter <= $number; $counter += 1) {
   echo "<option value=\"$djname[$counter]\">$djname[$counter]</option>
   ";
}
?></select></td></tr><tr><td><p align="center">
<input type="hidden" name="e1fc" value="" ></td>
<input type="hidden" name="e1v" value="<?php echo $e1 ?>" >

</tr></table></td>
									<td bgcolor="#CCCCCC" align="center" width="95">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><p align="center">
<select size="1" onchange="fcs()" name="f1">
<option selected value="<?php echo $f1 ?>"><?php echo $f1 ?></option>
<option>----------</option>
<?php
for ( $counter = 1; $counter <= $number; $counter += 1) {
   echo "<option value=\"$djname[$counter]\">$djname[$counter]</option>
   ";
}
?></select></td></tr><tr><td><p align="center">
<input type="hidden" name="f1fc" value="" ></td>
<input type="hidden" name="f1v" value="<?php echo $f1 ?>" >

</tr></table></td>
									<td bgcolor="#CCCCCC" align="center" width="95">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><p align="center">
<select size="1" onchange="fcs()" name="g1">
<option selected value="<?php echo $g1 ?>"><?php echo $g1 ?></option>
<option>----------</option>
<?php
for ( $counter = 1; $counter <= $number; $counter += 1) {
   echo "<option value=\"$djname[$counter]\">$djname[$counter]</option>
   ";
}
?></select></td></tr></table>
<input type="hidden" name="g1fc" value="" >
<input type="hidden" name="g1v" value="<?php echo $g1 ?>" >

</td>
								</tr>

Link to comment
https://forums.phpfreaks.com/topic/99646-solved-loop-help/
Share on other sites

if you want to loop that *entire* page out up to a said number of times, you would just put it all in a for () loop as explained in the post above.

 

I don't know about changing the variable *names* with an incrementing value, but I think someone else on here would if you wait long enough. I've never needed to have an incrementing value in a variable name before so that's why I know nothing about it, I'm sure there is a section in the php manual on it but I do think I've briefly looked over it before.

Link to comment
https://forums.phpfreaks.com/topic/99646-solved-loop-help/#findComment-509782
Share on other sites

Wel this is actuly a row in a table. And its for a timehsheet generator. but differnt radio sites will have a differnt amount of shifts threw out the day. So I will need this to repeat depending on how many shifts they set up in the config.

 

So for the var them selfs should I set them up as somthing like..

 

$t[1]

$t[1]a

$a[1]

 

Then I could just put in the $1 in the loop. That part im not sure about is now cause I have loops inside of there if I put the { at the beginging and the } at the end of the row will that cuase any issues for the other loops that are inside of the larger loop. And will somthing like $t[1]a work?

Link to comment
https://forums.phpfreaks.com/topic/99646-solved-loop-help/#findComment-510094
Share on other sites

ok Im half way there but im confused about how to put a loop call inside a loop right now I have...

 

<?php
for ( $i = 1; $i <= $numbers; $i += 1) {
echo "<tr><td width=\"65\" align=\"center\" height=\"40\" bgcolor=\"#CCCCCC\"><font class=\"time\">$t[$i]</font><br><font class=\"time\">$ta[$i]</font></td>
<td bgcolor=\"#CCCCCC\" align=\"center\" width=\"94\"><div align=\"center\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td>
<p align=\"center\">
<select size=\"1\" onchange=\"fcs()\" name=\"a$i\" >
<option selected value=\"$a[$i]\">$a[$i]</option>
<option>----------</option>
<?php
for ( $counter = 1; $counter <= $number; $counter += 1) {
echo \"<option value=\"$djname[$counter]\">$djname[$counter]</option>\";
}
?>
</select></td></tr>
<tr><td><input type=\"hidden\" name=\"afc[1]\" value=\"\" ></td></tr></table></div></td>
";}?>

 

But the problum is that the loop inside the loop comes out looking like this when the page loads.

 

<?php

for (  = 1;  <= 35;  += 1) {

echo "<option value=""></option>";

}

?>

What do I do to make this work?

Link to comment
https://forums.phpfreaks.com/topic/99646-solved-loop-help/#findComment-510292
Share on other sites

ok Im half way there but im confused about how to put a loop call inside a loop right now I have...

 

<?php

for ( $i = 1; $i <= $numbers; $i += 1) {

echo " ... <option>----------</option>

<?php

 

for ( $counter = 1; $counter <= $number; $counter += 1)

        {

echo \"<option value=\"$djname[$counter]\">$djname[$counter]</option>\";

}

...

 

But the problum is that the loop inside the loop comes out looking like this when the page loads.

 

<?php

for (  = 1;  <= 35;  += 1) {

echo "<option value=""></option>";

}

?>

What do I do to make this work?

 

 

Look again.... you have put the loop *INSIDE* of your 'echo' call. You have to terminate the echo call, perform the loop to echo the changing data and then echo any additional HTML after the loop.

 

Simple mistake to make - hard for you to find if you don't think about it.

Link to comment
https://forums.phpfreaks.com/topic/99646-solved-loop-help/#findComment-510330
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.