ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

'Most Read' query results behaviour

June 06, 2012 12:34pm

Subscribe [1]
  • #1 / Jun 06, 2012 12:34pm

    jonwrightmedia

    75 posts

    I used some code I found on here to create a ‘most read’ widget, which is meant to display only the top five most read posts.

    <ul class="icons">
    {exp:query limit="5" sql="select entry_id, view_count_one as cnt, url_title, title from exp_channel_titles 
       where view_count_one > 0 
       order by view_count_one desc"}
       <li><i class="icon-list-alt"></i><a href="http://{path=blog/view/{url_title}}">{title}</a></li>
    {/exp:query}
    </ul>

    However I get the results below:

    5 Key Steps in securing Business and Commercial Insurance in the UK
    5 Key Steps in securing Business and Commercial Insurance in the UK
    Wealth Dynamics Profile Test
    Wealth Dynamics Profile Test
    Watch This Space - My Book Launch in Sept 2012
    7 Common Mistakes Businesses Make - Mistake #6
    Watch This Space - My Book Launch in Sept 2012
    7 Common Mistakes Businesses Make - Mistake #6
    3 Critical Components for Effective KPIs
    Help others succeed and you will too
    Help others succeed and you will too
    3 Critical Components for Effective KPIs
    7 Common Mistakes Businesses Make - Mistake #7
    7 Common Mistakes Businesses Make - Mistake #7

    As you can see it’s not limited to five and several entries are repeated. Any ideas why?

    I’m using MSM if that affects things at all.

  • #2 / Jun 07, 2012 2:09pm

    Dan Decker

    7338 posts

    Hi jonparadise2,

    With the query module, you don’t limit as a parameter, you LIMIT as part of the SQL query itself:

    <ul class="icons">
    {exp:query sql="select entry_id, view_count_one as cnt, url_title, title from exp_channel_titles 
       where view_count_one > 0 
       order by view_count_one desc LIMIT 5"}
       <li><i class="icon-list-alt"></i><a href="http://{path=blog/view/{url_title}}">{title}</a></li>
    {/exp:query}
    </ul>

    EDIT: to clarify, the Query module supports the limit= parameter, but it is used for pagination. You still need to LIMIT within your SQL statement.

    Cheers,

  • #3 / Jun 08, 2012 4:37am

    jonwrightmedia

    75 posts

    Thanks Dan.

  • #4 / Jun 12, 2012 12:09pm

    Dan Decker

    7338 posts

    Hey Jon,

    My pleasure!

    If there is anything else I can do, please let me know.

    Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases