Solved

MYSQL - LIKE with variable and wildcard - Syntax help

Posted on 2010-08-15
3
658 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:TumacLumber
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
Comment Utility
$q="SELECT poID FROM in_transit_summary WHERE poID LIKE '".$poID."%' group by poID";

need quotes
0
 
LVL 58

Expert Comment

by:cyberkiwi
Comment Utility
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.
0
 

Author Closing Comment

by:TumacLumber
Comment Utility
Thanks.  Had my single quote in wrong places...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now