Jump to content

Creating Select List in 15 min intervals


CBaZ

Recommended Posts

I need it to display like the followiong

  • <option value="00:15">15mins</option>
  • <option value="00:30">30mins</option>
  • <option value="00:45">45mins</option>
  • <option value="01:00">1Hr</option>
  • <option value="01:15">1:15Hr</option>
  • <option value="01:30">1:30Hr</option>
  • and so on.

Here is the code I've tried thus far not producing any of the right results.

<?php
$options = array(); $min15=array('00','15');
   foreach (range(0,23) as $fullhour) {
      $parthour = $fullhour > 12 ? $fullhour - 12 : $fullhour;
       foreach($min30 as $int){
           if($fullhour > 11){
               $options[$fullhour.".".$int]=$parthour.":".$int." PM";
           }else{
               if($fullhour == 0){$parthour='12';}
               $options[$fullhour.".".$int]=$parthour.":".$int." AM" ;
           }
       }
   }
echo '<option value="'.$options.'">'.$options.'</option>';[/background]


?>

What?? Why do you have min15 and min30, but never use min15 or define min30?

 

This is a basic list of the times.

for($hour=0; $hour<=23; $hour++){
   for($mins=0; $mins<60; $mins=$mins+15){
      echo "{$hour}:{$mins}";
   }
}

Yeah I mean I didn't put a line break it in or anything because it was for you to LEARN from and then adjust your code, but it definitely works. It is absolutely NOT possible for the code I posted to output 24:60. (It also needs to have some adjustment to convert the trailing :0 to :00 but yeah.)

 

If you tried changing your code, post your new code. If not, do that first.

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.