Welcome Guest, Not a member yet? Register   Sign In
db table joining issue? or, is there a better way?
#1

[eluser]FireMe[/eluser]
ok, I think I may have a database joining issue or is there a better way or doing what I want, So first let me set the scene. I have a table called quotes, where has 'ID', 'USER_ID', 'FILE_ID' and other fields that are not that important to this.

so on my view I am listing all the quotes for that user id, then I decide I wanted to add a thumbnail image for the file, so i need to somehow get the 'path' field from my file table, so i decide to do the following join?

Code:
function get_all_quotes($user_id){
$this->db->select('*');
$this->db->from('quotes');
$this->db->where('quotes.user_id', $user_id);
$this->db->join('file', 'file.id = quotes.file_id');
$query = $this->db->get();
if($query->num_rows() > 0){
  foreach($query->result() as $row){
   $data[]=$row;
  }
  return $data;
}
else {
}
return false;
    }

which works fine and i get the image thumbnail on the view, but i lose the ID field from the 'QUOTES' table because of the join it overides the ID with the FILE_ID?

print_r bellow

Code:
Array ( [0] => stdClass Object ( [id] => 47 [user_id] => 6 [file_id] => 47 [status] => Quoted [price] => 19.99 [path] => image1.jpg ) [1] => stdClass Object ( [id] => 48 [user_id] => 6 [file_id] => 48 [status] => Quoted [price] => 5.99 [path] => image2.jpg ) )

or is there any easier way than joining the table to get the path field from the file table


Messages In This Thread
db table joining issue? or, is there a better way? - by El Forum - 09-18-2013, 02:44 AM
db table joining issue? or, is there a better way? - by El Forum - 09-18-2013, 07:57 AM
db table joining issue? or, is there a better way? - by El Forum - 09-18-2013, 08:45 AM
db table joining issue? or, is there a better way? - by El Forum - 09-18-2013, 09:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB