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
Share on other sites

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.