
03-30-2003, 03:44 PM
|
|
Newbie
|
|
Join Date: Mar 2003
Posts: 23
|
|
How could I do a keyword search of a column in a table.
For instance, say the column type is a string and I want to look for a particular word within that string.
Any advice would be most welcomed.
|

03-30-2003, 04:31 PM
|
|
Account Suspended
|
|
Join Date: Mar 2003
Location: BC, Canada
Posts: 21
|
|
SELECT *
FROM mytable
WHERE keyword
LIKE '%$key%'
Good luck,
|

03-30-2003, 08:40 PM
|
|
Web Hosting Master
|
|
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
|
|
Using the 'LIKE' operator
PHP Code:
mysql_query("SELECT * FROM <table> WHERE <field> LIKE '%<match text>%'");
Hope it helps.
__________________
nu-metal.org :: coming soon
|

03-31-2003, 03:22 AM
|
|
Junior Guru Wannabe
|
|
Join Date: Feb 2003
Location: Wilmington, NC
Posts: 44
|
|
PHP Code:
mysql_query("SELECT * FROM <table> WHERE <field> LIKE '%".addslashes(<match text>)."%'");
Use Addslashes() to prevent SQL injection....
__________________
Andy Rockwell - SolidPHP, Inc. Owner / Founder
SolidPHP.com - E-commerce software solutions powering 4000+ Customers
* Take a look at our brand new billing software SPBAS today!
* Developers of PHPAudit and iono PHP anti-piracy licensing and billing solutions
|

03-31-2003, 04:34 AM
|
|
Web Hosting Master
|
|
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
|
|
Ahh good point, didn't even think of that 
__________________
nu-metal.org :: coming soon
|

03-31-2003, 06:23 AM
|
|
Junior Guru Wannabe
|
|
Join Date: Mar 2003
Location: Minneapolis, MN
Posts: 36
|
|
Quote:
Originally posted by HTTPeasy
PHP Code:
mysql_query("SELECT * FROM <table> WHERE <field> LIKE '%".addslashes(<match text>)."%'");
Use Addslashes() to prevent SQL injection....
|
Make sure not to think of addslashes() as a cure-all, you should do as much data validation as you can if your source is user input. Also, remember to make note of your magic quote's if working with user input.
Of course, this all only has any meaning if the poster is using PHP, which s/he didn't mention 
|

03-31-2003, 06:41 AM
|
|
Web Hosting Master
|
|
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
|
|
Good point, I'm 99% sure that they're using PHP though 
__________________
nu-metal.org :: coming soon
|

04-01-2003, 04:10 PM
|
|
Junior Guru Wannabe
|
|
Join Date: Mar 2003
Location: Montreal
Posts: 32
|
|
SELECT *
FROM mytable
WHERE keyword
LIKE '% $key %'
You may want to pad your $key variable
at the beginning, end, or both depending
on how you want your search to function.
You may not want someone looking for 'cat'
to end up looking at web content talking
about catalysts catastrophies and categories.
my 2 Cents
__________________
www.WebHostingMontreal.com
frank@WebHostingMontreal.com
|

04-01-2003, 06:31 PM
|
|
Web Hosting Master
|
|
Join Date: Dec 2002
Location: NY, NY
Posts: 3,975
|
|
select * from tablename where keyword like (search string here)
put % in front for searches lik sdsadadKeyword
put % behing for searches like Keywordsdsdmsdsd
and put % on both sides for before and after like: dsdsdsdKeywordfdffsfsf
sorry for confusing you lol
|

04-01-2003, 09:32 PM
|
|
Web Hosting Master
|
|
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
|
|
haha, yeah that's right  % is just like using * or something in say regex...
__________________
nu-metal.org :: coming soon
|
Related posts from TheWhir.com
|
| Title |
Type |
Date Posted |
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|