Reputation: 5568
I have a products detail page and I need to be able to call the appropriate work area from the database. My columns are called: ils1275_work_area, ils975_work_area, etc.
All I need are a couple of words, so I am only returning a row. Ordinarily to call the column with my SQL, I would do (in CodeIgniter):
function get_misc($item)
{
$this->db->select($item);
$this->db->where('lang', 'en');
return $this->db->get('all_misc')->row();
}
And then in my PHP I would echo $row->ils1275_work_area
. Since on a single products detail page for multiple products, I need more flexibility than that, I need to do something like:
$row->{$laser}_work_area
But that doesn't work. (I am supplying the value for $laser in my controller). What syntax should I use?
Upvotes: 0
Views: 251
Reputation: 2431
Try forming the name of the variable as its own variable:
$workArea = "{$laser}_work_area";
$val = $row->$workArea;
Upvotes: 0