• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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*


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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