Re: Loop Question
| From: | Jed R. Brubaker | Date: | Sat, 18 Oct 2003 19:14:14 +0000 |
| Subject: | Re: Loop Question | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-166620@lists.php.net to get a copy of this message | ||
Well duh. Thanks so much!
"Robert Cummings" <robert@interjinn.com> wrote in message
news:1066503788.3855.2.camel@blobule.suds...
> See changes below.
>
> Cheers,
> Rob.
>
> On Sat, 2003-10-18 at 14:57, Jed R. Brubaker wrote:
> > 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++)
>
> for ($i = 0; $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++)
>
> for ($j = 0; $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!
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> --
> .------------------------------------------------------------.
> | InterJinn Application Framework - http://www.interjinn.com |
> :------------------------------------------------------------:
> | An application and templating framework for PHP. Boasting |
> | a powerful, scalable system for accessing system services |
> | such as forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for |
> | creating re-usable components quickly and easily. |
> `------------------------------------------------------------'