Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
Proper way to use DBUtil:: to select rows containing highest values in a given field?
  • Posted: 13.07.2007, 00:34
     
    alarconcepts
    rank:
    Professional Professional
    registered:
     April 2004
    Status:
    offline
    last visit:
    21.01.08
    Posts:
    2723
    I looked over the class, but didn't find a function for this in particular, or at least didn't recognize any as such.

    In a module table that has a "hits" field (denoting pageviews) how would I grab say the 5 rows that have the highest value in this field? I could grab all the records and perform this with PHP, but the object itself seems the logical place to do it. What would be the most "compliant" way to achieve this result?

    Thanks for any advice,

    - John

    --
    Photography | PHP | Other
  • Posted: 13.07.2007, 00:45
     
    alarconcepts
    rank:
    Professional Professional
    registered:
     April 2004
    Status:
    offline
    last visit:
    21.01.08
    Posts:
    2723
    I so often find that typing something out leads me to an answer ... it seems that simply by sorting by the column I need, and passing a limit, it works. :)

    Code

    $records = = pnModAPIFunc('ModName', 'user', 'getall', array('start'=>-1, 'limit'=>XYZ, 'order'=>'hits', 'dir'=>'desc'));


    Very nice!




    --
    Photography | PHP | Other

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula