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]


?>

Link to comment
Share on other sites

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}";
   }
}

Link to comment
Share on other sites

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.

Edited by Jessica
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.