Loop Question
| From: | Jed R. Brubaker | Date: | Sat, 18 Oct 2003 18:57:30 +0000 |
| Subject: | Loop Question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-166618@lists.php.net to get a copy of this message | ||
Hi! I am trying to loop through two different database calls with two for
statements, one embedded in the other.
for ($i; $i < $codeset_rows; $i++)
{
$codeset_row = $this->database->fetch_array($codeset_query);
$codesys_query = $this->database->query("select
codesys.codesys_index,
codesys.code_name,
codesys.code_value
from codesys
where codesys.codeset_ID = ".$codeset_row['codeset_ID']);
$codesys_rows = $this->database->num_rows($codesys_query);
for ($j; $j < $codesys_rows; $j++)
{
echo "Blah, blah, blah....";
}
}
The current set up means that the first loop should cycle twice, and the
second loop should cycle 6 times the first time and 2 times the second.
So here is the question: $j doesn't unset when the loop ends. So when it
comes around the second time, $j still = 6 and since $codesys_rows = 2, it
skips the loop. I can fix this by putting an
if ($j)
{unset($j);}
right before the second loop. However, it seems that there should be some
more efficient way to do this.
Ideas?
Thanks!