floorfiller Posted April 6, 2012 Share Posted April 6, 2012 Hey everyone, Been a while since I posted. I hope everyone is doing well. I've built a couple of for() loops into my program and I'm getting some inconsistent results. The first loop I made was just a simple counter looking like this: <select name="event_name"> <?php for($x = 1; $x <= 50; $x++){ if($x < 10){ echo "<option value=\"$x\">Event 0$x:"; echo "</option>"; } else{ echo "<option value=\"$x\">Event $x:"; echo "</option>"; } } ?> </select> This code works perfect. The 1st entry in my drop down list is event 1, then event 2 etc. now i have basically the same code on the another selection: <select name="date" <?php for($x = 1; $x <= 24; $x++){ if($x < 10){ echo "<option value=\"$x\">0$x:00 EST"; echo "</option>"; } else{ echo "<option value=\"$x\">$x:00 EST"; echo "</option>"; } } ?> </select> however the generated code on this call starts with a result on 2 instead of 1 giving me 02:00 EST instead of 01:00 EST. I'm sure I could work around this by declaring some additional variables, but i'm just trying to figure out why i'm seeing different results between these two loops? any thoughts? thanks in advance for your help Quote Link to comment https://forums.phpfreaks.com/topic/260432-inconsistencies-with-for-loops/ Share on other sites More sharing options...
floorfiller Posted April 6, 2012 Author Share Posted April 6, 2012 wow i'm a moron. sorry guys i just answered my own question. it seems in the <select> statement i forgot to close the braces on the 2nd one. and that is throwing things off. sorry i'd delete the post, but i didn't see a delete button. Quote Link to comment https://forums.phpfreaks.com/topic/260432-inconsistencies-with-for-loops/#findComment-1334862 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.