1

I have this lines of code,

$val = self::$db->select('*')->select('a.id')->select("CONCAT(user_profile.firstname,' ',user_profile.middlename,' ',user_profile.lastname) AS user_name")->from('a')->join('user_profile', 'po.user_id = user_profile.id')->get()->result();

In this query, It will select all data in the rows. There is a column that is selected, "modified_by". I would like to use that to get the corresponding user_profile.firstname.

I tried this lines of code but not working,

$val = self::$db->select('*')->select('a.id')->select('a.modified_by' as modifier)->select("CONCAT(user_profile.firstname,' ',user_profile.middlename,' ',user_profile.lastname) AS user_name")->select('user_profile.firstname where user_profile.id = modifier ')->from('a')->join('user_profile', 'po.user_id = user_profile.id')->get()->result();
Dj Genexxe
  • 27
  • 5
  • 1
    You should put the entirety of: `select('a.modified_by' as modifier)` inside those single quotes. That's the most obvious problem I see. So basically change it to: `select('a.modified_by as modifier')`. – Keeleon Jun 16 '16 at 14:26
  • @DjGenexxe Can you elaborate more about this question – Abdulla Nilam Jun 16 '16 at 16:51

1 Answers1

0

To further @Keeleon's comment you can combine SELECT statements using commas so your code above is perfectly legal as:

$this->db->select('*, a.id, a.modified_by as modifier, CONCAT(user_profile.firstname,' ',user_profile.middlename,' ',user_profile.lastname) AS user_name)-> .... ->get()

It does look like you're doing a subquery though, that get's a big hairy when it comes to using codeigniter's default function - you can use this answer as a means to get that sorted out: https://stackoverflow.com/a/16303021/3629438

But the gist of it is to separate out the queries before combining them.

Community
  • 1
  • 1
acupofjose
  • 2,159
  • 1
  • 22
  • 40