Fork me on GitHub

Proper way to use DBUtil:: to select rows containing highest values in a given field?  Bottom

  • 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
  • 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!


  • 0 users

This list is based on users active over the last 60 minutes.