Re: How to limit a WHILE statement?
| From: | CC Zona | Date: | Mon, 02 Apr 2001 23:06:51 +0000 |
| Subject: | Re: How to limit a WHILE statement? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-46703@lists.php.net to get a copy of this message | ||
In article <B6EE5287.4002%lindsay@dingos.net>,
lindsay@dingos.net (Lindsay Adams) wrote:
> Two ways:
> Do it in PHP
> add a counter and test for it at the end of the while loop
> if ==20 then break;
>
> Easier, do it in your query:
> tack LIMIT 20 on the end of your query, and you will only get the first
> 20 hits from your database.
>
>
>
> On 4/2/01 3:54 PM, "Bob Stone" <bstone98@yahoo.com> wrote:
>
> > Dear PHP Helpers,
> >
> > What is your recommendation on limiting a while
> > statement so that it only iterates a maximum of 20
> > times?
Third way: use a for loop instead of the while (same concept at the first
suggestion, just slightly different methology).
for($i=0;$i<20;$i++)
{
blah
}
--
CC