![]() |
consulting variable - 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: consulting variable (/showthread.php?tid=61279) |
consulting variable - pompeu - 04-06-2015 Hi, how to save a sql query in a variable ? , for example: I have the following query: Code: $country = $this-> db- > query ("select country from users where email = '$email' and password = '$password' " ) ; I want to store that user's country in a variable : Example $var_country = Brazil Code: $var_country = $country; But when I use the variable gives the following error: Code: A PHP Error was encountered Thanks ^^ RE: consulting variable - CroNiX - 04-06-2015 You didn't grab the result from the executed query and access the 'country' column from the result PHP Code: $country = $this-> db- > query ("select country from users where email = '$email' and password = '$password' " ) ; RE: consulting variable - pompeu - 04-06-2015 (04-06-2015, 02:06 PM)CroNiX Wrote: You didn't grab the result from the executed query and access the 'country' column from the result sorry, did not get it right , could explain me better , could give a real example of how would this query ? thanks mate RE: consulting variable - CroNiX - 04-06-2015 I thought I did give an example? The above should work assuming the initial code you supplied is correct. RE: consulting variable - pompeu - 04-06-2015 (04-06-2015, 02:57 PM)CroNiX Wrote: I thought I did give an example? The above should work assuming the initial code you supplied is correct. the above code returns an error: Code: A PHP Error was encountered follows as did Code: //Conexão e consulta com DB Thanks ^^ RE: consulting variable - CroNiX - 04-06-2015 Your original query ($query) most likely failed. Did you supply a valid $email and $pass? Try this (for testing): PHP Code: $query = $this->db->query("select email, country, pass from users where email = '$email' and pass = '$pass'")->result(); RE: consulting variable - pompeu - 04-06-2015 Cronix, I had not got it right the concept of using the queries in CI but is now resolved. I like that and it worked : Code: $query = $this-> db-> query ("select email, country , password from users where email = '$email' and password = '$password' " ) ; Thanks very much Problem resolved ^^ |