Select Query remove space automatically - 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: Select Query remove space automatically (/showthread.php?tid=69938) |
Select Query remove space automatically - Luca4k4 - 02-01-2018 Hi, I'm a new member of the forum This is my first experience with Codeigniter and my absolute first with a framework php. Today i'm writing a function in my model to get information from a mysql table. I do: $this->db->select('Web Developer'); .... But i get the error: "SELECT 'Web' 'Developer' FROM ... Column Web doesn't exist " CI has automatically replaced space with apex, splitting my single column in two columns. Why does it happen? How could i prevent it? Thank you in advance! RE: Select Query remove space automatically - Elias - 02-01-2018 Hi! You need to pass table name to select() method. Table name can't contents spaces. Look at this https://www.codeigniter.com/userguide3/database/query_builder.html RE: Select Query remove space automatically - Martin7483 - 02-01-2018 (02-01-2018, 08:26 AM)Elias Wrote: Hi! No, you pass column names to the select method. For the rest you are correct. Table names as well as column names can't have a space in them RE: Select Query remove space automatically - Kaosweaver - 02-01-2018 The ability to have alias names is what the code is seeing here. The space indicates that their will be an alias declared. You will need to setup the query like so: PHP Code: $this->db->query("SELECT `Web Developer` FROM table"); RE: Select Query remove space automatically - Elias - 02-01-2018 (02-01-2018, 08:35 AM)Martin7483 Wrote:(02-01-2018, 08:26 AM)Elias Wrote: Hi! Yes) I confused with the get() method..) RE: Select Query remove space automatically - Luca4k4 - 02-02-2018 Okay, all clear! But MySQL allow to have space in column names. As alternative i used that: $this->db->select('`'.$job.'`', false); because $job is passed from myself, so i should be safe or i don't ? |