CBaZ Posted January 27, 2013 Share Posted January 27, 2013 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] ?> Quote Link to comment https://forums.phpfreaks.com/topic/273708-creating-select-list-in-15-min-intervals/ Share on other sites More sharing options...
Jessica Posted January 27, 2013 Share Posted January 27, 2013 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}"; } } Quote Link to comment https://forums.phpfreaks.com/topic/273708-creating-select-list-in-15-min-intervals/#findComment-1408604 Share on other sites More sharing options...
CBaZ Posted January 27, 2013 Author Share Posted January 27, 2013 gives me the output 24:60 Quote Link to comment https://forums.phpfreaks.com/topic/273708-creating-select-list-in-15-min-intervals/#findComment-1408608 Share on other sites More sharing options...
Barand Posted January 27, 2013 Share Posted January 27, 2013 Then you got it wrong. Jessica's code goes from 0:0 to 23:45 Quote Link to comment https://forums.phpfreaks.com/topic/273708-creating-select-list-in-15-min-intervals/#findComment-1408609 Share on other sites More sharing options...
CBaZ Posted January 27, 2013 Author Share Posted January 27, 2013 <?php for($hour=0; $hour<=23; $hour++){ for($mins=0; $mins<60; $mins=$mins+15){ echo "{$hour}:{$mins}"; } } echo "<option value={$hour}:{$mins};>{$hour}:{$mins}</option>"; ?> produces the result of 24:60 Quote Link to comment https://forums.phpfreaks.com/topic/273708-creating-select-list-in-15-min-intervals/#findComment-1408611 Share on other sites More sharing options...
salathe Posted January 27, 2013 Share Posted January 27, 2013 produces the result of 24:60 Oh, really? http://codepad.viper-7.com/4JSphY Quote Link to comment https://forums.phpfreaks.com/topic/273708-creating-select-list-in-15-min-intervals/#findComment-1408612 Share on other sites More sharing options...
Jessica Posted January 27, 2013 Share Posted January 27, 2013 (edited) 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 January 27, 2013 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/273708-creating-select-list-in-15-min-intervals/#findComment-1408614 Share on other sites More sharing options...
CBaZ Posted January 27, 2013 Author Share Posted January 27, 2013 hmm must be a server issue then i get 24:60 strange. Quote Link to comment https://forums.phpfreaks.com/topic/273708-creating-select-list-in-15-min-intervals/#findComment-1408615 Share on other sites More sharing options...
PFMaBiSmAd Posted January 27, 2013 Share Posted January 27, 2013 it's because you are using the value after the end of the loop, not inside the loop, where it was designed to be used. Quote Link to comment https://forums.phpfreaks.com/topic/273708-creating-select-list-in-15-min-intervals/#findComment-1408618 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.