Reply to Re: Search in Mysql...

Your name:

Reply:


Posted by Robert on 12/17/39 11:55

Searching in MySQL can be tricky. If you are wanting to search in MySQL
the correct code examles are true:

(1) Search with wildcards (note "s" in wildcard)
SELECT * FROM table WHERE col LIKE '%search%'
-or-
SELECT DISTINCT * FROM table WHERE col LIKE '%search%'

Notice the % (percent sign), this means it will match "search" with
ANYTHING before -OR- after the search term. But if you only want to
search AFTER the term, you would only use the % sign AFTER. Example:
SELECT * FROM table WHERE col LIKE 'search%'

Same for searching BEFORE the search term. Example:
SELECT * FROM table WHERE col LIKE '%search'
-- This will pull anything that starts with * (wildcard) and includes
"search" after it.

Theres also another way to search by using the wildcard (notice: no
"s") search.
It's somewhat like the first explaination, but different.

SELECT * FROM table WHERE col LIKE 'somthing_'
Notice the _ (underscore) -- This means MySQL will get everything from
the term "something" plus anything after "something" -- for example:
"somethings" will be selected as found in the search. The _ is a
wildcard modifier which will tell MySQL how many wildcards it will
search. For example, if you used 3 underscores ___ it will look for the
search term then anything that has up to 3 wildcards. For example:
SELECT * FROM table WHERE col LIKE 'something___'

You can also use it from a starting point. For example:
SELECT * FROM table WHERE col LIKE '___something'
This is basically the samething as 'something___' but it will get up to
3 wildcards BEFORE the search term.

Helpful? If you're confused you can always visit (MySQL 5+)
http://mysql.com/doc/refman/5.0/en/select.html -or- (MySQL 4+)
http://mysql.com/doc/refman/4.1/en/select.html

Hope this helps, -Rob


jbk@ewebs.gr wrote:
> Hello...
> i have a table which contains a column named "ask" and a column named
> "per"...
> my think is that i want to search in "ask" and echo the data stored in "per"
> for this entry...
> How do i do this?
> Thanx in advance!
> JBK

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация