Solved

MYSQL - LIKE with variable and wildcard - Syntax help

Posted on 2010-08-15
3
672 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
ID: 33442053
$q="SELECT poID FROM in_transit_summary WHERE poID LIKE '".$poID."%' group by poID";

need quotes
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33442062
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
ID: 33446191
Thanks.  Had my single quote in wrong places...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL left join performance 4 44
running code or pseudo code of table structure 5 30
Insert values are dynamic 11 51
FrontEnd tools to create web database application 7 82
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

837 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