severndigital Posted August 5, 2007 Share Posted August 5, 2007 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 Link to comment https://forums.phpfreaks.com/topic/63390-solved-interesting-loop-cant-figure-it-out/ Share on other sites More sharing options...
Barand Posted August 5, 2007 Share Posted August 5, 2007 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"; } } ?> Link to comment https://forums.phpfreaks.com/topic/63390-solved-interesting-loop-cant-figure-it-out/#findComment-315973 Share on other sites More sharing options...
tibberous Posted August 5, 2007 Share Posted August 5, 2007 <select name="timein" id="timein"> <?php for($t=0; $t<96; $t++) echo "<option>".(1+(floor($t/4)%12)).":".($t%4*15).($t%4?"":"0")." ".(($t<44||$t>91)?"am":"pm")."</option>"; ?> </select> Barand's option is cool too. Link to comment https://forums.phpfreaks.com/topic/63390-solved-interesting-loop-cant-figure-it-out/#findComment-315975 Share on other sites More sharing options...
dbo Posted August 5, 2007 Share Posted August 5, 2007 I was going to try to help but I'm so drunk I can't hardly read. I'm sorry Link to comment https://forums.phpfreaks.com/topic/63390-solved-interesting-loop-cant-figure-it-out/#findComment-315976 Share on other sites More sharing options...
severndigital Posted August 5, 2007 Author Share Posted August 5, 2007 Thanks. while they all actually worked. suggestion #3 worked the best for me. I did what they did . Link to comment https://forums.phpfreaks.com/topic/63390-solved-interesting-loop-cant-figure-it-out/#findComment-316019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.