MySQL Wildcards - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Databases - MySQL, SQL, Oracle, Access and others

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-21-2009, 10:02 AM   #1 (permalink)
Junior Member
 
Join Date: Mar 2009
Posts: 2
Exclamation MySQL Wildcards

This is slowly but surely wearing at me, and I need help.

The problem is this. I'm trying to create a search function of sorts with SQL LIKE and eventually a field of keywords. I've been testing it on the title for now. The LIKE works fine without wildcards, but when I try to put wildcards in the statement, where nearly every site tells me to, it does not work. I've used % and *. The website is hosted on a linux server and I was using PHP to access the MySQL server, if that helps any.

my test code peice as well, if that helps:
$query = sprintf("SELECT title, subtitle, button, price, ItemNo, instock, search1, search2 FROM inventory WHERE title LIKE '%naruto%' ORDER BY title ASC");

Thank you for your help.
falcatrecon is offline   Reply With Quote
Sponsored Links
Old 03-21-2009, 04:09 PM   #2 (permalink)
Junior Member
 
freegamegallery.com's Avatar
 
Join Date: Mar 2009
Posts: 6
Default Re: MySQL Wildcards

I wonder if the problem is with running your sql string through sprintf.
sprintf is going to attempt to process the % signs first, and the net result is that your % signs will be disappearing from the sql query.
Check out the sprintf docs:
PHP: sprintf - Manual

I do the exact same thing you do in my system, however I dont use sprintf.
Try this instead:
$query = "SELECT title, subtitle, button, price, ItemNo, instock, search1, search2 FROM inventory WHERE title LIKE '%naruto%' ORDER BY title ASC";

If you HAVE to use sprintf for some other reason, then try escaping the % symbols.

I hope that helps!
freegamegallery.com is offline   Reply With Quote
Old 03-22-2009, 10:01 AM   #3 (permalink)
Junior Member
 
Join Date: Mar 2009
Posts: 2
Default Re: MySQL Wildcards

Thank you! It works perfectly now.
falcatrecon is offline   Reply With Quote
Old 03-24-2009, 08:20 AM   #4 (permalink)
Junior Member
 
Join Date: Mar 2009
Location: UK
Posts: 7
Default Re: MySQL Wildcards

Quote:
Originally Posted by freegamegallery.com
I wonder if the problem is with running your sql string through sprintf.
sprintf is going to attempt to process the % signs first, and the net result is that your % signs will be disappearing from the sql query.
Check out the sprintf docs:
PHP: sprintf - Manual

I do the exact same thing you do in my system, however I dont use sprintf.
Try this instead:
$query = "SELECT title, subtitle, button, price, ItemNo, instock, search1, search2 FROM inventory WHERE title LIKE '%naruto%' ORDER BY title ASC";

If you HAVE to use sprintf for some other reason, then try escaping the % symbols.

I hope that helps!
Thanks for your support, i really had the same doubt
Jennysmith is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 07:11 AM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting