• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mySQL into Active Record

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
$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
$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
'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.



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:

$this->db->select('diary.id AS diaryID');
$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

Thanks man! I'll give that a shot and let you know how it goes Smile

That worked brilliantly.

*manly hug*

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.