Be careful with nested FOR statements Mar07 '05
Something I just learned today – the HARD way, mind you...
Unless I was doing something completely wrong – I noticed, in PHP, that you can’t issue a FOR statement within another FOR statement, and use the same temporary variable for each.
It will just cause your page to hang, and never load.
Here is a brief sample of the syntax I had:
for ($i=0; $i<$image_share_numrows; $i++)
{
$image_share_row = mysql_fetch_array($image_share_result);
if ($image_share_row[4] == 1)
{
for ($i=0; $i<$specials_numrows; $i++)
{
...
}
}
}
Notice the variables in white. They can’t (or so it seems) be the same.
To correct the problem, I just changed the variables in the nested FOR statement to a different letter – k, for instance.
Categories: PHP ![]()
Add Feedback (view all)
Leave feedback
matthom
is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago.
Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.
Similar Entries
- PHP switch statements are great (36 recent visits)
- Nested TITLE attributes (1 recent visits)
Stats
2 unique visits since August 2008