how to deal with .com in SQL query? |
I am building this string to use in a query.
$where= $where="email=".$this->session->userdata('userid')." AND campaign=".$this->session->userdata('campaign'); In my example this correctly becomes: "[email protected] AND campaign=Apple" But when I try running the following line $crud->set_relation('bus_comp','business_components','bus_comp',$where); I get an error: SELECT COUNT(*) AS `numrows` FROM `business_components` WHERE `email` = `richb201@gmail`.`com` AND `campaign` = `Apple` How do I stop the "." in the email address from being taken as just a "."?
proof that an old dog can learn new tricks
Your correct example seems to be wrong, see you miss the ' ' in the values. Your correct example should be like this in order to work:
"email = '[email protected]' AND campaign = 'Apple'"
Thanks. But how to put a quote around $this->session->userdata('userid')? Do I use an escape char like this?
$where= $where="email=/'".$this->session->userdata('userid')."/'. AND campaign=/'".$this->session->userdata('campaign')."/'";
proof that an old dog can learn new tricks
You don't need to, if your id is the int type, it goes without quote, and if it is string type, it already have it.
In the Grocery crud documentation (which is based on Codeigniter) the field ($where) being asked for is:
void set_relation( string $field_name , string $related_table, string $related_title_field [, mixed $where [, string $order_by ] ] ) I have noticed that same syntax "mixed $where" in the codeigniter documentation. What does that mean? Is this not what they are asking for?: $where= $where="email=".$this->session->userdata('userid')." AND campaign=".$this->session->userdata('campaign');
proof that an old dog can learn new tricks
No. See the structute of a query is like this:
OPERATION table_fields FROM table START_CONDITION condition_field = condition_value Look at this example: "SELECT name, age FROM people_table WHERE id = 1" In the void set_relation function: $field_name = "name, age"; $related_table = "people_table"; $related_title_field = " id"; $where = 1;
If you read the documentation it states that the where clause is the same as CodeIgniters.
PHP Code: $userid = $this->session->userdata('userid'); As far as your .com on the email just use double quotes not single. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |