Jump to content

[SOLVED] interesting loop, can't figure it out.


severndigital

Recommended Posts

ok here is what I intend to do.

 

1. create a select form field

2. populate the form field with a while loop that generates the value and the text for the option

3. for each while loop i want to generate 4 different field entries.

 

basically I want to display 4 time values in the box like this.

 

1:00 am

1:15 am

1:30 am

1:45 am

 

and then goto the next hour

 

2:00 am

2:15 am

2:30 am

2:45 am

 

and so on.

 

What i have so far i think is on the correct path:

 


//start the box
echo '<select name="timein" id="timein">';
$counter = 0;
while($counter < 12){
	if($counter == 0){
		$timeFront = 12;
		$valFront = "00";
		$valMerd = "am";
	} else {
		$timeFront = $counter;
		$valFront = $counter;
		$valMerd = "am";
	} //take care of 00:00 being 12:00am

	//make a :15,:30,:45 for each hour
                // this is where i am stuck

	$regTime = '' . $timeFront . ':' . $timeBack . ' ' . $valMerd . '';	
	$armyTime = '' . $valFront . ':' . $timeBack . '';
echo '<option value="' . $armyTime . '">' . $regTime . '</option>';
$counter = $counter + 1;
}//end whileloop

 

any one have suggestion?? or a better quicker way to do it?

 

Thanks in advance,

chris

 

 

try

<?php


for ($h = 1; $h <= 12; $h++)
{
    for ($m=0; $m<=45; $m+=15)
    {
        $t = mktime($h, $m, 0);
        $armytime = date ('H:i', $t);
        $regtime = date ('g:i a', $t);
        echo "<option value='$armytime'>$regtime</option>\n";
    }
}
?>

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.