Jump to content

Loop Question


xander85

Recommended Posts

Hi All,

 

I'm jumping back into PHP and I have a basic loop question that I'm struggling with. I'm using a "date picker" code to select times during the day and then using a javascript to calculate the total hours for the day. However, I'm struggling with the loop to print out the fields. I need a loop that will print the following:

 

first iteration:

value = 1

value = 2

value = 0

 

second iteration:

value = 2

value = 3

value = 1

 

The code I'm using is the following:

for ($id = 1; $id <=45 ; $id++)
		{
			?>

			<?php
			if($id % 2)
			{
			?>
			<div id="labor_template_day_100">
			<input type="text" name="time1000<?php echo $id; ?>""/> 
			<input type="text" name="time1000<?php echo $id+1;  ?>" />
			<?php 
			}
			?>
			<input type="hidden" id="emp<?php echo $id-1; ?>hours" value="0"/> 
			<?php 
			if($id % 2)
			{
			?>
			</div>	
			<?php
			}
		}

 

This prints:

first iteration:

value = 1

value = 2

value = 0

 

Inserts just a hidden form field, then:

 

value = 1

value = 2

value = 2

 

See below:

<div id="labor_template_day_100">
			<input type="text" name="time10001" id="time10001" size="7" value="06:00 AM" onChange="CalcHrs('time10001', 'time10002', '0');"/> 
			<input type="text" name="time10002" id="time10002" size="7" value="06:00 AM" onChange="CalcHrs('time10001', 'time10002', '0');" />

							<input type="hidden" id="emp0hours" value="0"/> 
							</div>	

							<input type="hidden" id="emp1hours" value="0"/> 

							<div id="labor_template_day_100">
			<input type="text" name="time10003" id="time10003" size="7" value="06:00 AM" onChange="CalcHrs('time10003', 'time10004', '2');"/> 
			<input type="text" name="time10004" id="time10004" size="7" value="06:00 AM" onChange="CalcHrs('time10003', 'time10004', '2');" />
							<input type="hidden" id="emp2hours" value="0"/> 
							</div>	

							<input type="hidden" id="emp3hours" value="0"/> 

 

I have a feeling this is something basic I need to change.

Link to comment
https://forums.phpfreaks.com/topic/247402-loop-question/
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.