Jump to content

inconsistencies with for() loops.


floorfiller

Recommended Posts

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 :)

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.