Solved

MYSQL - LIKE with variable and wildcard - Syntax help

Posted on 2010-08-15
3
671 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Selecting specific rows 3 53
MySQL Init Waits 25 96
showing numeric numbers 2 36
Help With Query That Causes "WARNING: MySQL server has gone away" Error 3 29
Creating and Managing Databases with phpMyAdmin in cPanel.
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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