On Monday July 4 2016 11:38, in comp.lang.php, "super70s"
<supe...@super70s.invalid> wrote:
> (This question is for everyone but R.Wieser)
>
> I have a "Most Popular Pages" page on my site, with the page titles and
> brief descriptions listed based on the number of page views. I need to
> limit the number of page titles to 100 instead of having it display
> every single page title in the database, which is what it's doing now. I
> think this is the pertinent code:
>
> <?while ($rshome = mysql_fetch_array($cmdartcat)) { ?>
>
> Is there an easy way to accomplish what I want by modifying this somehow?
Others have described the smart, easy way to do this by using the SQL "LIMIT"
clause in your query. So, I'll address a non-SQL alternative, just for
completeness sake:
Instead of
<?while ($rshome = mysql_fetch_array($cmdartcat)) { ?>
you could place a counter in your loop code; something like
<?
for ($count = 0;
$count < 100 && $rshome = mysql_fetch_array($cmdartcat) ;
++$count) {
?>
But, the SQL "LIMIT 100" clause would be your best bet, here.
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request