Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
order_by random?
  • Hi, For the life of me, I can't figure out how to randomize results from an ORM query. The API tells me this... order_by( $property, $direction = ASC ) : If I put anything but a column for the property, I get something like this: Fuel\Core\Database_Exception [ 1054 ]: Unknown column 't0.RAND()' in 'order clause' [ SELECT `t0`.`design_id` AS `t0_c0`, `t0`.`design_file` AS `t0_c1`, `t0`.`designer` AS `t0_c2` FROM `designs` AS `t0` ORDER BY `t0`.`RAND()` ASC ] Should I be using something else? The only discussion of "random" in the ORM API is for randomizing count() Thanks! - Calvin
  • The query builder's identifier quote method can't deal with functions without parameters (it identifies a function by looking for a double quote, not by brackets). I suggest you'll report this as an issue https://github.com/fuel/core/issues so it can be looked at.
  • Actually I think this should work when RAND() is passed in a Database_Expression object:
    $query->order_by(DB::expr('RAND()'));
    
    But the Orm doesn't support this yet, if you need this make a bugreport on http://github.com/fuel/orm/issues
  • Thanks, guys!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion