Link to home
Start Free TrialLog in
Avatar of TumacLumber
TumacLumber

asked on

MYSQL - LIKE with variable and wildcard - Syntax help

I am having problem with syntax for a query that grabs a variable value and then a wildcard

$q="SELECT poID FROM in_transit_summary WHERE poID LIKE ".$poID."% group by poID";

I keep getting  invalid qry error
ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Since you are already using double quotes, you can leave $poID in the string and let php variable substitution take place.

$q="SELECT poID FROM
in_transit_summary WHERE poID
LIKE '$poID%' group by poID";

To be clear, if poID is a string (varchar), then you need single quotes around it when searching.  If it is a number, it will need to be cast to a varchar first, and the same LIKE expression.
Avatar of TumacLumber
TumacLumber

ASKER

Thanks.  Had my single quote in wrong places...