Welcome Guest, Not a member yet? Register   Sign In
Can anyone please help me write this using active records?
#1

[eluser]behnampmdg3[/eluser]
Hello;
I am trying to use active records on this but I need a little bit of help.

Thank you.

Code:
SELECT *,
`sincity_events`.`id` AS EID,
query2.PHOTOS, GROUP_CONCAT(sincity_events_celebrities.id) as CELEBS,
GROUP_CONCAT(sincity_celebrities.name) as CELEB_NAME

FROM (`sincity_events`)

LEFT JOIN `sincity_events_celebrities` ON `sincity_events_celebrities`.`event_id` = `sincity_events`.`id`
LEFT JOIN `sincity_celebrities` ON `sincity_celebrities`.`id` = `sincity_events_celebrities`.`celebrity_id`


LEFT OUTER JOIN (SELECT COUNT(id) AS PHOTOS, event_id FROM sincity_event_photos  ) AS query2 ON query2.event_id = sincity_events.id

WHERE `sincity_events`.`date` >= '13-01-1'
AND `sincity_events`.`date` <= '13-01-31'
GROUP BY `sincity_events`.`id`
ORDER BY `title` asc
I have taken it very far but I dont know how to add the select Left Outer Join.
Code:
$this->db->select('*, sincity_events.id AS EID, GROUP_CONCAT(sincity_events_celebrities.id) as CELEBS, , GROUP_CONCAT(sincity_celebrities.name) as CELEB_NAME');
    $this->db->from('sincity_events');
    $this->db->join('sincity_events_celebrities', 'sincity_events_celebrities.event_id = sincity_events.id', 'left');
    $this->db->join('sincity_celebrities', 'sincity_celebrities.id = sincity_events_celebrities.celebrity_id', 'left');
    $this->db->where('sincity_events.date >=', $first);
    $this->db->where('sincity_events.date <=', $last);
    $this->db->group_by("sincity_events.id");
    $this->db->order_by("title", "asc");
#2

[eluser]pisio[/eluser]
Yo ! When you have long query like this is better to use $this->db->query( " YOUR_LONG_QUERY " );
Active Records is not optimal solution for every think.
Now with AR you make this query and after 1 year you shout to edit it, you will have problems.
At last project I do I make this query : http://sphotos-f.ak.fbcdn.net/hphotos-ak...6128_n.jpg
So think again is good idea to use AR or just query
#3

[eluser]behnampmdg3[/eluser]
[quote author="pisio" date="1358078708"]Yo !
Now with AR you make this query and after 1 year you shout to edit it, you will have problems.
[/quote]What? Why should I edit it after 1 year????
#4

[eluser]Otemu[/eluser]
There isn't any difference between LEFT JOIN and LEFT OUTER JOIN




Theme © iAndrew 2016 - Forum software by © MyBB