Welcome Guest, Not a member yet? Register   Sign In
string based custom ordering in active record
#8

[eluser]TheFuzzy0ne[/eluser]
Aaah, now I see how it works.

The active record class is designed for simple queries. Is there any reason you can't just stick to a manual query like you did before?

You could probably do this:
Code:
$this->db->select('i.id, condition, description, created_at, updated_at, category, latitude, longitude, status,          
    d.device_token, d.facebook, d.preferred, d.email, d.phone');
$this->db->select("CONCAT('$url', `image_url_original`) AS `image_url_original`", false);
$this->db->select("CONCAT('$url', `image_url_mid`) AS `image_url_mid`", false);
$this->db->select("CONCAT('$url', `image_url_thumb`) AS `image_url_thumb`", false);
$this->db->select('FIELD(`category`,
    'Auto & Accessories', 'Couch', 'Bed', 'Desk & Office', 'Bike & Scooter', 'Tools',
    'Leisure', 'Iron & Wood', 'Cabinet', 'Kitchen & Accessories', 'Refrigerator & Appliances',
    'Toys & Games', 'Chair', 'Table', 'Garden & Terrace', 'TV, HIFI & Computers', 'General Item') AS `sort_col`', false);

$this->db->from('item as i');
$this->db->join('device as d', 'i.device_id = d.device_token');

$this->db->where('created_at > DATE_SUB(UTC_TIMESTAMP(), INTERVAL 24 HOUR)');
$this->db->where('i.status', 'shared');

if($language === 'nl_NL') {
    $this->db->order_by('sort_col', 'asc');
} else {
    $this->db->order_by('category', 'asc');
}

I haven't tested it, but it should work if there are no syntax errors.

Please let me know how you get on.


Messages In This Thread
string based custom ordering in active record - by El Forum - 03-23-2013, 04:55 AM
string based custom ordering in active record - by El Forum - 03-23-2013, 06:33 AM
string based custom ordering in active record - by El Forum - 03-23-2013, 09:35 AM
string based custom ordering in active record - by El Forum - 03-23-2013, 10:02 AM
string based custom ordering in active record - by El Forum - 03-23-2013, 08:15 PM
string based custom ordering in active record - by El Forum - 03-24-2013, 04:11 AM
string based custom ordering in active record - by El Forum - 03-24-2013, 05:09 AM
string based custom ordering in active record - by El Forum - 03-24-2013, 07:09 AM
string based custom ordering in active record - by El Forum - 03-27-2013, 03:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB