Jump to content

[SOLVED] Increasing a number in a variable name


Maracles

Recommended Posts

I am trying to use the below loop to echo the following code but I am having two problems;

 

1. Each time the loop runs I need the variable $day1 to increase to $day2. Is it possible to use the $i variable here somehow?

2. The line here is incorrect, I think because I am unsure how to create a nested loop like is required here.

 

'.if ($day1 > 0) {echo $day1;}else {echo '0';}.'

 

Can anyone help me get this working? I'm very grateful for all help.

 


<?php 

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

echo '<label>Day <b>'.$i.'</b> - $</label>';
echo '<input class="input" type="text" name="day'.$i.'" maxlength="10" size="10" value="'.if ($day1 > 0) {echo $day1;}else {echo '0';}.' " disabled="disabled"/> $';
echo '<input class="input" type="text" name="day'.$i.'new" maxlength="10" size="10" /><br />';

}
?>				

here you go

 

<?php 

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

echo '<label>Day <b>'.$i.'</b> - $</label>';
echo '<input class="input" type="text" name="day'.$i.'" maxlength="10" size="10" value="'.((${"day$i"} > 0)  ? ${"day$i"} : '0').' " disabled="disabled"/> $';
echo '<input class="input" type="text" name="day'.$i.'new" maxlength="10" size="10" /><br />';

}
?>

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.