![]() |
There's a dollar(sign) in variable name - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: There's a dollar(sign) in variable name (/showthread.php?tid=62941) |
There's a dollar(sign) in variable name - rhyszz - 09-09-2015 Is that possible to get the data when their is a dollar(sign) in variable. Example: my column name is price_in_u$ ** this is the column name in my database then i use model and controller to query and get data ( i have no problem here) this is my code when i display the data ** PHP Code: echo 'Price in US: ' $comp_prod->prince_in_u$ the error i got is: syntax error, unexpected '$', expecting ',' or ';' is there a way i can use the dollar(sign) ? even escaping the string is not working. PHP Code: echo 'Price in US: ' $comp_prod->prince_in_u/$ RE: There's a dollar(sign) in variable name - Diederik - 09-10-2015 You could try: PHP Code: $tmpVar = 'prince_in_u$'; Or PHP Code: echo 'Price in US: ' . $comp_prod->{'prince_in_u$'}; Another idea would be to fetch the result as an array instead of an object. PHP Code: foreach ($query->result_array() as $row) Or as a last resort you could change the column name in your database. PS, in your code you forgot the dot sign to concatenate the string and the object. RE: There's a dollar(sign) in variable name - rhyszz - 09-10-2015 PHP Code: $temp_var = 'Price_IN_U$'; this one works! hooray! haha i already come up with this idea but i also include the comp-prod that makes my code echo it. thanks for this! new learning. RE: There's a dollar(sign) in variable name - mwhitney - 09-10-2015 Something else to consider is that you can alias the column name in your select statement, like this: PHP Code: // Although I don't recommend adding '*' in the array, |