Solved

MYSQL - LIKE with variable and wildcard - Syntax help

Posted on 2010-08-15
3
673 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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