Concatenating the symbol in recordset of a PHP

In my record set I am taking countrycode using GET operator and sending it to the query as a parameter and I am using LIKE operator for this query like this.

$query_getzone = "SELECT distinct LocationId FROM all_dropdown WHERE LocationId LIKE '".$country.".'-%'";

I am getting an error 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-%'' at line 1'. Please help me with this.

Answers


try this,

$query_getzone =  "SELECT distinct LocationId FROM all_dropdown WHERE LocationId LIKE '$country-%'";;

You have extra quote(') and a dot (.) in query.

Change like this:

"... WHERE LocationId LIKE '" . addslashes($country) . "-%'";

You have given extra (dot) . and (quote) ' in the concatenation

remove it and it will be as : LIKE '".$country."-%'

and so whole query becomes :

$query_getzone = "SELECT distinct LocationId FROM all_dropdown WHERE LocationId LIKE '".$country."-%'";

This will work.


Try this

$query_getzone = "SELECT distinct LocationId FROM all_dropdown WHERE LocationId LIKE ". "'$country-%'";

will work.


Need Your Help

Require help in Writing Query

sql mysql database query-optimization

The following image have been uploaded to show what I am trying to do and what I wanted out of it

How to work around the ValueError: array is too big error?

python arrays numpy scipy orange

I've got a scipy sparse matrix (csr:Compressed Sparse Row matrix). I'd like to use Orange's feature selection methods (Orange.feature.scoring.score_all (InfoGain/MDL)). However, from my understandi...