Page 1 of 1

Simple if condition makes for loop infinite?

Posted: Sat Nov 15, 2008 3:35 am
by JAB Creations
The following for loop works just fine until I uncomment the if conditions, can someone kindly explain why please?

Code: Select all

for ($i = 1; $i <= $pages; $i++)
 {
  echo '<option ';
  //if ($i = $_GET['p']) {echo 'selected="selected" ';}
  echo 'value="'.$i.'">';
  //if ($i = $_GET['p']) {echo 'You are currently viewing ';}
  echo 'Page '.$i.'</option>'."\n";
 }

Re: Simple if condition makes for loop infinite?

Posted: Sat Nov 15, 2008 3:46 am
by alex.barylski
See point #5 in my blog entry. :P

Your using a assignment instead of comparison in both IF's that might have something to do with it. ;)

Re: Simple if condition makes for loop infinite?

Posted: Sat Nov 15, 2008 3:49 am
by JAB Creations
DOH!

Thanks for pointing out the obvious...

"No question is so difficult to answer as that to which the answer is obvious." - George Bernard Shaw

Re: Simple if condition makes for loop infinite?

Posted: Sat Nov 15, 2008 3:54 am
by alex.barylski
Haha...it happens...your eyes get tired and you miss stupid little things like that...

p.s-Your situation doesn't apply to my blog either, so nevermind about that. :P

Re: Simple if condition makes for loop infinite?

Posted: Sat Nov 15, 2008 3:55 am
by JAB Creations
I'm not tired right now...I have an odd sleeping pattern at the moment. :mrgreen:

I'm reading your blog right now, thanks for mentioning it.