Ordering a helper query

Ordering a helper query

nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
edited November 2012 in General
Hi,

The code below does not work.

To populate a SELECT box, I want an alphabetically sorted list from tblRegions. The only functionality which I could find documented was the order method?

Kind regards,

Nathan

$out['tblRegions'] = $db
->select( 'tblRegions', 'RID as value, RName0 as label' )
->order('RName0')
->fetchAll();

Replies

  • nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
    Please let me know how to sort the query to populate the SELECT inputs in an Editor form, and add this to the documentation.
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Your query doesn't work because the `select` method does not result a `Query` instance, but rather a `Result` as documented here: http://editor.datatables.net/docs/current/php/class-DataTables.Database.html#_select .

    The `select` is just a short hand for quick queries. If you want something more that what `select` provides then you need to use the `Query` object which is fully documented here:
    http://editor.datatables.net/docs/current/php/class-DataTables.Database.Query.html

    For example:

    [code]
    $db
    ->query( 'select' )
    ->table( 'tblRegions' )
    ->get( 'RID as value', 'RName0 as label' )
    ->order( 'RName0 asc' )
    ->exec()
    ->fetchAll();
    [/code]

    Allan
  • nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
    Thanks Allan.
This discussion has been closed.