I am trying to pass the name of a column as a variable to a PHP database query.
the hard coded syntax works perfectly and is:
select max([257612cr]) as price from Price_TekwaniPrice where customeraccount='DAY001'
When I pass the variable I get error trying to get property ofnon object. my syntax is:
$query = $this->db->query("
select max(['$product']) as price from Price where customeraccount='$customer'
");
I also tried:
$query = $this->db->query("
select max(".$product.") as price from Price where customeraccount='$customer'
");
I have confirmed that the variables are being passed correctly. the syntax for '$customer' works perfectly so just passing the $product variable as a column name is proving cumbersome.
I am using php with codeigniter. any advice welcome.
Thanks as always,
$thisis not an object.$productis a string ? Isn't it an object, triggering some __toString() method when used in a concatenation context ?$sql = 'select max() etc';echo $sql;then$query = $this->db->query($sql);