CodeIgniter Forums
How to use variable in Active record SELECT - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to use variable in Active record SELECT (/showthread.php?tid=26067)



How to use variable in Active record SELECT - El Forum - 01-05-2010

[eluser]shinokada[/eluser]
I need to use a variable in $this->db->select();

Something like this,

$this->db->select('$tableid,name');

Code:
function findOrphans($segment, $id, $db_table){
     $tablename = explode("-", $db_table);
    $tableid = $tablename[1]."_id";
    
    $data = array();
     $this->db->select('$tableid,name');

But I am not sure if I can.

Can anyone tell me how to please?


How to use variable in Active record SELECT - El Forum - 01-05-2010

[eluser]gigas10[/eluser]
I don't believe you want to put single quotes around a variable name in active record. So:
Code:
[b]$this->db->select($tableid,'name');[/b]



How to use variable in Active record SELECT - El Forum - 01-05-2010

[eluser]wowdezign[/eluser]
Did you try this?
Code:
function findOrphans($segment, $id, $db_table){
     $tablename = explode("-", $db_table);
    $tableid = $tablename[1]."_id";
    
    $data = array();
     $this->db->select($tableid.',name');