hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : SQL Help
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

SQL Help

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 03-30-2003, 03:44 PM
cosmic_bird cosmic_bird is offline
Newbie
 
Join Date: Mar 2003
Posts: 23

SQL Help


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.

Reply With Quote


Sponsored Links
  #2  
Old 03-30-2003, 04:31 PM
packetnews packetnews is offline
Account Suspended
 
Join Date: Mar 2003
Location: BC, Canada
Posts: 21
SELECT *
FROM mytable
WHERE keyword
LIKE '%$key%'


Good luck,

Reply With Quote
  #3  
Old 03-30-2003, 08:40 PM
digitok digitok is offline
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

Reply With Quote
Sponsored Links
  #4  
Old 03-31-2003, 03:22 AM
solidphp solidphp is offline
Junior Guru Wannabe
 
Join Date: Feb 2003
Location: Wilmington, NC
Posts: 44
Security

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

Reply With Quote
  #5  
Old 03-31-2003, 04:34 AM
digitok digitok is offline
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

Reply With Quote
  #6  
Old 03-31-2003, 06:23 AM
Tweakin Tweakin is offline
Junior Guru Wannabe
 
Join Date: Mar 2003
Location: Minneapolis, MN
Posts: 36
Re: Security

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

Reply With Quote
  #7  
Old 03-31-2003, 06:41 AM
digitok digitok is offline
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

Reply With Quote
  #8  
Old 04-01-2003, 04:10 PM
W-H-Mtl W-H-Mtl is offline
Junior Guru Wannabe
 
Join Date: Mar 2003
Location: Montreal
Posts: 32
my 2 Cents

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

Reply With Quote
  #9  
Old 04-01-2003, 06:31 PM
ilyash ilyash is offline
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

Reply With Quote
  #10  
Old 04-01-2003, 09:32 PM
digitok digitok is offline
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

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?