CodeIgniter Forums
how to deal with .com in SQL query? - 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: how to deal with .com in SQL query? (/showthread.php?tid=77512)



how to deal with .com in SQL query? - richb201 - 09-10-2020

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 "."? 


RE: how to deal with .com in SQL query? - Omar Crespo - 09-10-2020

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'"


RE: how to deal with .com in SQL query? - richb201 - 09-10-2020

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')."/'";


RE: how to deal with .com in SQL query? - Omar Crespo - 09-10-2020

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.


RE: how to deal with .com in SQL query? - richb201 - 09-10-2020

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');


RE: how to deal with .com in SQL query? - Omar Crespo - 09-10-2020

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;


RE: how to deal with .com in SQL query? - InsiteFX - 09-10-2020

If you read the documentation it states that the where clause is the same as CodeIgniters.

PHP Code:
$userid   $this->session->userdata('userid');
$campaign $this->session->userdata('campaign');

$where = array('email =' => $userid,'campaign =' => $campaign); 

As far as your .com on the email just use double quotes not single.