Welcome Guest, Not a member yet? Register   Sign In
Active record doesn't support ORDER BY FIELD()
#1

[eluser]LoRdCoStE[/eluser]
Hi,
as title say actually active record class does not support FIELD function in db->order_by.

The problem is that A.R. try to escape the function.

ex:

Code:
$this->db->order_by("FIELD(id, 129084,126792)");

produce:

ORDER BY FIELD(id, `129084`, `126792)`

but the correct query is:

ORDER BY FIELD(`id`, '129084', '126792')

a temporary fix (not a good fix) is:
Code:
/* Location: ./system/database/DB_active_rec.php */

function order_by($orderby, $direction = '')
    {
        if (strpos($orderby, 'FIELD(') !== FALSE || strpos($orderby, 'FIELD (') !== FALSE)
        {
            $this->ar_orderby[] = $orderby;
            return $this;
        }
        
        // ...
    }

Hope to see that implemented in the next version of CI.
Bye


Messages In This Thread
Active record doesn't support ORDER BY FIELD() - by El Forum - 12-03-2009, 10:00 PM
Active record doesn't support ORDER BY FIELD() - by El Forum - 12-04-2009, 12:50 AM
Active record doesn't support ORDER BY FIELD() - by El Forum - 09-11-2013, 11:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB