Sam
Sam

Reputation: 51

Converting Query in Codeigniter format

I have a query

SELECT        l.id,l.name,l.city,l.email,l.phone,l.status,l.source,l.leadCreatedTime,l.organizationId
FROM    (
    SELECT  id
    FROM    leads
where removed='0'
    ORDER BY
            id
    LIMIT 40000
    ) o
JOIN    leads l
ON      l.id = o.id
ORDER BY
    l.id

I want to convert this query in Codeigniter format for eg

$this->db->select('l.id,l.name,l.city,l.email,l.phone,l.status,l.source,l.leadCreatedTime,l.organizationId');
$this->db->from('leads');

Im having problem in the 8th line of query where the fetched data is defined as o how am I suppose to write that in CI

Upvotes: 0

Views: 98

Answers (2)

Deepak
Deepak

Reputation: 523

can u test my code it may help you as it is codegniter format

$this->db- >select('l.id,l.name,l.city,l.email,l.phone,l.status,l.source,l.leadCreatedTime,l.organizationId');
$this->db->from('(SELECT id FROM leads where removed="0" ORDER BY id LIMIT 40000) o');
$this->db->join('leads l', 'l.id = o.id');
$this->db->order_by('l.id');
$result=$this->db->get();
$show=$result->result_array();

it is not in fully codeigniter format in sub query but it help you.

Enjoy code.

Upvotes: 2

Rahul K
Rahul K

Reputation: 413

This May works for you:

$this->db->select('l.id,l.name,l.city,l.email,l.phone,l.status,l.source,l.leadCreatedTime,l.organizationId');

        $this->db->from('leads o');

        $this->db->join('leads l', 'l.id = o.id');

        $this->db->order_by("l.id", "asc");

        $q = $this->db->get();

Upvotes: 0

Related Questions