Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #16820 > unrolled thread

Limit "most popular" to 100

Started bysuper70s <super70s@super70s.invalid>
First post2016-07-04 10:38 -0500
Last post2016-07-06 14:02 +0200
Articles 5 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  Limit "most popular" to 100 super70s <super70s@super70s.invalid> - 2016-07-04 10:38 -0500
    Re: Limit "most popular" to 100 Richard Damon <Richard@Damon-Family.org> - 2016-07-04 09:06 -0700
      Re: Limit "most popular" to 100 "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-07-04 18:11 +0200
      Re: Limit "most popular" to 100 super70s <super70s@super70s.invalid> - 2016-07-05 22:32 -0500
        Re: Limit "most popular" to 100 "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-07-06 14:02 +0200

#16820 — Limit "most popular" to 100

Fromsuper70s <super70s@super70s.invalid>
Date2016-07-04 10:38 -0500
SubjectLimit "most popular" to 100
Message-ID<super70s-BB47CD.10383304072016@boina.datemas.de>
(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?

[toc] | [next] | [standalone]


#16822

FromRichard Damon <Richard@Damon-Family.org>
Date2016-07-04 09:06 -0700
Message-ID<fQvez.67639$F_5.10789@fx23.iad>
In reply to#16820
On 7/4/16 8:38 AM, super70s 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?
>

This is more of a mysql issue than a php issue. If you add a limit cause 
to your query, you can limit how many records you receive.

You could do a php only solution, adding a counter to the loop. 
Something similar to:

<?$cnt=0;
while (++$cnt<=100 && $rshome = mysql_fetch_array($cmdartcat)) { ?>

[toc] | [prev] | [next] | [standalone]


#16823

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2016-07-04 18:11 +0200
Message-ID<nle1r1$d23$1@solani.org>
In reply to#16822
On 04.07.2016 at 18:06, Richard Damon wrote:

> On 7/4/16 8:38 AM, super70s wrote:
>
>> (This question is for everyone but R.Wieser)

Nonsense.  This is Usenet.

>> <?while ($rshome = mysql_fetch_array($cmdartcat)) { ?>
>>
>> Is there an easy way to accomplish what I want by modifying this somehow?
> 
> This is more of a mysql issue than a php issue. If you add a limit cause
> to your query, you can limit how many records you receive.

And that's what should be done for performance reasons.

> You could do a php only solution, adding a counter to the loop.
> Something similar to:
> 
> <?$cnt=0;
> while (++$cnt<=100 && $rshome = mysql_fetch_array($cmdartcat)) { ?>

And consider to avoid the mysql extension, which has been deprecated
long ago, and has been removed from the official php.net distribution as
of PHP 7.0.0.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#16827

Fromsuper70s <super70s@super70s.invalid>
Date2016-07-05 22:32 -0500
Message-ID<super70s-4AE521.22324705072016@boina.datemas.de>
In reply to#16822
In article <fQvez.67639$F_5.10789@fx23.iad>,
 Richard Damon <Richard@Damon-Family.org> wrote:

> This is more of a mysql issue than a php issue. If you add a limit cause 
> to your query, you can limit how many records you receive.
> 
> You could do a php only solution, adding a counter to the loop. 
> Something similar to:
> 
> <?$cnt=0;
> while (++$cnt<=100 && $rshome = mysql_fetch_array($cmdartcat)) { ?>

That seems to have done the trick! Much obliged.

I just didn't want the page to get really huge by displaying all the 
posts in the db. I don't know why the original author didn't use your 
coding to limit it to 100 because at the top it says "Here are the 100 
most popular posts on...etc."

[toc] | [prev] | [next] | [standalone]


#16832

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2016-07-06 14:02 +0200
Message-ID<nlis19$vt5$2@solani.org>
In reply to#16827
On 06.07.2016 at 05:32, super70s wrote:

> In article <fQvez.67639$F_5.10789@fx23.iad>,
>  Richard Damon <Richard@Damon-Family.org> wrote:
> 
>> You could do a php only solution, adding a counter to the loop. 
>> Something similar to:
>>
>> <?$cnt=0;
>> while (++$cnt<=100 && $rshome = mysql_fetch_array($cmdartcat)) { ?>
> 
> That seems to have done the trick! Much obliged.
> 
> I just didn't want the page to get really huge by displaying all the 
> posts in the db.

Good thinking.  However, why do you retrieve all posts from the DB then
in the first place?

-- 
Christoph M. Becker

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web