|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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; |
|
#2
|
||||
|
||||
|
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: |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > there has to be an easier way to search |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|