Welcome Guest, Not a member yet? Register   Sign In
mySQL into Active Record
#1

[eluser]KJTED[/eluser]
Hello everyone,
I'm having a problem converting a traditional MySQL query into one that uses the Active Record class.

The query I have is
Code:
$sql = 'SELECT * , diary . id as diaryID FROM `diary` JOIN jobs on jobs . id = diary . jobID JOIN users on users . id = diary . userID JOIN clients On clients . id = jobs . clientID LIMIT 0, 30 ';

I've managed to get this so far
Code:
$this->db->select('*');
$this->db->from('diary');
$this->db->join('jobs', 'jobs.id = diary.jobID');
$this->db->join('users', 'users.id = diary.userID');
$this->db->join('clients', 'clients.id = jobs.clientID');
$this->db->where('jobs.id', $this->id);

but I'm having problems with putting the following slice into my Active Record query
Code:
'SELECT * , diary . id as diaryID

Does anyone know how to do this? I've looked into the documentation but there doesn't seem to be anything on this.

Thanks

KJ
#2

[eluser]champs[/eluser]
If it's not taking to anything, it's the spaces. I've never used that style, but here's how I would write the same query:

Code:
<?php
$this->db->select('*');
$this->db->select('diary.id AS diaryID');
$this->db->from('diary');
$this->db->join('jobs',    'jobs.id=diary.jobID');
$this->db->join('users',   'users.id=diary.userID');
$this->db->join('clients', 'clients.id=jobs.clientID');
$this->db->limit(0, 30);
?>

... and don't let anyone tell you to just use straight queries/bindings :p
#3

[eluser]KJTED[/eluser]
Thanks man! I'll give that a shot and let you know how it goes Smile
#4

[eluser]KJTED[/eluser]
That worked brilliantly.

*manly hug*




Theme © iAndrew 2016 - Forum software by © MyBB