Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old September 14th, 2003, 08:20 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
there has to be an easier way to search

I am trying to search my database for specific words as some words will not be allowed on my website. This is the admin tool.
I have put all this in objects already but I think that there is an easier way of doing this search, even though it does work



$result = mysql_query("SELECT * FROM products
WHERE UPPER(GR_ProductName) like '".strtoupper('fun')."'
OR UPPER(GR_ProductName) like '".strtoupper('sexy')."'
OR UPPER(GR_ProductName) like '".strtoupper('dolls')."'
OR UPPER(GR_ProductName) like '".strtoupper('pics')."'
OR UPPER(GR_ProductName) like '".strtoupper('tripper')."'
OR UPPER(GR_ProductName) like '".strtoupper('gun')."'
OR UPPER(GR_ProductDescription) like '".strtoupper('fun')."'
OR UPPER(GR_ProductDescription) like '".strtoupper('sexy')."'
OR UPPER(GR_ProductDescription) like '".strtoupper('dolls')."'
OR UPPER(GR_ProductDescription) like '".strtoupper('pics')."'
OR UPPER(GR_ProductDescription) like '".strtoupper('tripper')."'
OR UPPER(GR_ProductDescription) like '".strtoupper('gun')."'
OR UPPER(GR_SwopItem) like '" .strtoupper('fun')."'
OR UPPER(GR_SwopItem) like '".strtoupper('sexy')."'
OR UPPER(GR_SwopItem) like '".strtoupper('dolls')."'
OR UPPER(GR_SwopItem) like '".strtoupper('pics')."'
OR UPPER(GR_SwopItem) like '".strtoupper('tripper')."'
OR UPPER(GR_SwopItem) like '".strtoupper('gun')."'
AND GR_ShowProduct = '1' ");
$this->display_result = $result;
return true;

Reply With Quote
  #2  
Old September 14th, 2003, 10:49 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: there has to be an easier way to search

A couple things:
1. No need to convert everything to uppercase unless the columns are BLOBs. Text searches in MySQL are case insensitive.
2. column LIKE 'string' isn't going to do you much good since there are no wildcard characters. I think you mean: column LIKE '%string%'
3. You probably want parantheses around all those ORs. It might work as written, but your intent isn't as clear.
4. If you use arrays to store the words, it makes maintaining the list much easier.
5. Take a look at full text search. It may or may not be helpful to you.

Try this code instead:
php Code:
Original - php Code
  1.  
  2. $words = array('fun', 'sexy', 'dolls', 'pics', 'tripper', 'gun');
  3. $result = mysql_query("SELECT * FROM products WHERE ("
  4. ." GR_ProductName like '%".join("%' OR GR_ProductName like '%", $words)."%'"
  5. ." OR GR_ProductDescription like '%".join("%' OR GR_ProductDescription like '%", $words)."%'"
  6. ." OR GR_SwopItem like '%".join("%' OR GR_SwopItem like '%", $words)."%'"
  7. .") AND GR_ShowProduct = '1'");
  8. $this->display_result = $result;
  9. return true;

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > there has to be an easier way to search


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT