consulting variable |
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 ^^
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' " ) ;
(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
I thought I did give an example? The above should work assuming the initial code you supplied is correct.
(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 ^^
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();
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 ^^ |
Welcome Guest, Not a member yet? Register Sign In |