select order by fields value

Hi, I wonder if I could select query order by fields through builder or critiera

SELECT * FROM fruit ORDER BY FIELD(name, 'Banana', 'Apple', 'Pear', 'Orange'),

thanks



6.3k

Thanks, I guess I didn't explain myself clear, I am familar with find/phql, but I want to use ORDER BY FIELD, so it always return same order I wanted. I was after something phql support with modelManager, I guess I have to use raw query to do so.

Hi,

you can do quiet everything:

using ORM: https://docs.phalconphp.com/en/latest/reference/models.html#finding-records

using phql (a kind of high level query language): https://docs.phalconphp.com/en/latest/reference/phql.html#selecting-records

using query builder: https://docs.phalconphp.com/en/latest/reference/phql.html#creating-queries-using-the-query-builder

or even raw SQL: https://docs.phalconphp.com/en/latest/reference/phql.html#using-raw-sql



30.8k
// ORM
// Get first 100 virtual robots ordered by name
$robots = Robots::find(
    array(
        "type = 'virtual'",
        "order" => "name",
        "limit" => 100
    )
);

//PHQL
$phql   = "SELECT * FROM Formula\Cars ORDER BY Formula\Cars.name";
$query  = $manager->createQuery($phql);

// and so on