Re: Limit iterations on a foreach loop?
| From: | Robby Russell | Date: | Fri, 11 Feb 2005 16:36:29 +0000 |
| Subject: | Re: Limit iterations on a foreach loop? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-208531@lists.php.net to get a copy of this message | ||
On Thu, 2005-02-10 at 15:58 -0800, Brian Dunning wrote:
> I'm using an RSS feed that has WAY too much content, I only want the
> first 10. I'm outputting the array with a foreach loop: is there a way
> to limit it to only go through the first 10?
>
> Thanks,
>
> - Brian
>
Is this data coming from a database? If so, just set a limit at the end
of your query...
example: SELECT * FROM blog ORDER BY id DESC LIMIT 10;
..will return the latest 10 entries.
-Robby
--
/***************************************
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON | www.planetargon.com
* Portland, OR | robby@planetargon.com
* 503.351.4730 | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
* --- Now hosting Ruby on Rails Apps ---
****************************************/