Dark-Hawk Posted May 18, 2009 Share Posted May 18, 2009 Alright I'm creating a drop down menu that will be used to select a range of time. I ultimately want it to display 00, through 59 and am having issues creating a proper for loop to display 01, 02, etc. I know I'll need to use nested loops but I'm unsure exactly what to do. I was able to come up with/find: <? for($a=0; $a < 10; $a++){ for($b=0; $b < 10; $b++){ echo $a.$b.", "; } } ?> Which counts out to 99 .. I'm having issues getting it to break at 59. Link to comment https://forums.phpfreaks.com/topic/158586-solved-for-loop-to-output-01020359/ Share on other sites More sharing options...
Jibberish Posted May 18, 2009 Share Posted May 18, 2009 just change 10 to 6? <?php for($a=0; $a < 6; $a++){ for($b=0; $b < 10; $b++){ echo $a.$b.", "; } } ?> Link to comment https://forums.phpfreaks.com/topic/158586-solved-for-loop-to-output-01020359/#findComment-836406 Share on other sites More sharing options...
Dark-Hawk Posted May 18, 2009 Author Share Posted May 18, 2009 Hm it's working now .. when I first tried that it skipped several numbers for some reason. Thanks though. Link to comment https://forums.phpfreaks.com/topic/158586-solved-for-loop-to-output-01020359/#findComment-836408 Share on other sites More sharing options...
Maq Posted May 18, 2009 Share Posted May 18, 2009 If I understand you correctly, you could have just used a single loop: for($a=1; $a echo ($a} ?> Link to comment https://forums.phpfreaks.com/topic/158586-solved-for-loop-to-output-01020359/#findComment-836417 Share on other sites More sharing options...
Dark-Hawk Posted May 18, 2009 Author Share Posted May 18, 2009 Ah ok, that would've worked too, well thanks for the help, here's the code as it sits now working as I need it: <td><select name="hour1"> <? for($x = 1; $x <= 12; $x++) { ?> <option value="<? echo $x; ?>"><? echo $x; ?></option><? } ?> </select><b>:</b> <select name="minute1"> <? for($a=0; $a < 6; $a++){ for($b=0; $b < 10; $b++){ ?> <option value="<? echo "$a$b"; ?>"><? echo "$a$b"; ?></option> <? } }?> </select> <b>-</b> <select name="hour2"> <? for($x = 1; $x <= 12; $x++) { ?> <option value="<? echo $x; ?>"><? echo $x; ?></option><? } ?> </select><b>:</b> <select name="minute2"> <? for($a=0; $a < 6; $a++){ for($b=0; $b < 10; $b++){ { ?> <option value="<? echo "$a$b"; ?>"><? echo "$a$b"; ?></option><? } ?> <? } }?> </select> </td> Link to comment https://forums.phpfreaks.com/topic/158586-solved-for-loop-to-output-01020359/#findComment-836418 Share on other sites More sharing options...
Axeia Posted May 18, 2009 Share Posted May 18, 2009 Woaw, I'm impressed you can still read that.. for($b=0; $b < 10; $b++){ ?> <option value="<? echo "$a$b"; ?>"><? echo "$a$b"; ?></option> <? } }?> Is a lot more readable to me if it was typed down like say.. for($b=0; $b < 10; $b++){ echo "<option value='$a$b'>$a$b</option>"; } }?> And it's not adviced to use <? unless you're sure your script will ALWAYS run on a server with shorttags enabled. (use <?php instead) Link to comment https://forums.phpfreaks.com/topic/158586-solved-for-loop-to-output-01020359/#findComment-836443 Share on other sites More sharing options...
Dark-Hawk Posted May 18, 2009 Author Share Posted May 18, 2009 Yeah I went through and just finished changing it all over to be a bit easier to read. I'll keep that in mind about using <?php rather than short tags. Thanks Link to comment https://forums.phpfreaks.com/topic/158586-solved-for-loop-to-output-01020359/#findComment-836465 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.