Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Searching the MySQL database - one field, many rows?
Old 03-30-2006, 01:57 PM Searching the MySQL database - one field, many rows?
Junior Talker

Posts: 3
Location: Oslo, Norway
Trades: 0
Well, basically, I want to let my users search through "row1", "row2" and "row3" by only using one form field. My code currently looks like this (it's in PHP):
Code:
... AND `row1` LIKE \'' . $search_text . '\',
`row2` LIKE \'' . $search_text . '\',
`row3` LIKE \'' . $search_text . '\',
`row4` LIKE \'' . $search_text . '\''
However, that doesn't work. There are some other fields that are submitted, so that's why there's an "AND" at the beginning. I don't post the other parts since I know they work properly.

But how can I search through multiple rows, and show the database entry if it finds $search_text in at least one of the fields?
Amezis is offline
Reply With Quote
View Public Profile Visit Amezis's homepage!
 
 
Register now for full access!
Old 03-30-2006, 02:42 PM Re: Searching the MySQL database - one field, many rows?
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
You want to be using an AND/OR between each row's like statement.

Code:
... AND `row1` LIKE \'' . $search_text . '\',
OR `row2` LIKE \'' . $search_text . '\',
OR `row3` LIKE \'' . $search_text . '\',
OR `row4` LIKE \'' . $search_text . '\''
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 03-30-2006, 04:17 PM Re: Searching the MySQL database - one field, many rows?
Junior Talker

Posts: 3
Location: Oslo, Norway
Trades: 0
Thanks alot! It works now.

But if someone enter "word1%word2", to search the first row1 and find word1, and then find word2 in row3 or row2? (Basically, one word is in one row, another word is in another row. Both words are from the same form field.)
Amezis is offline
Reply With Quote
View Public Profile Visit Amezis's homepage!
 
Old 03-30-2006, 04:57 PM Re: Searching the MySQL database - one field, many rows?
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
If I understand you correctly in that case you will simply be returned more than one result. Your results will be in an array.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 04-01-2006, 11:17 PM Re: Searching the MySQL database - one field, many rows?
Novice Talker

Posts: 10
Trades: 0
get a search script that is already made.. much easier
__________________
The very best
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
gretty is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Searching the MySQL database - one field, many rows?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25079 seconds with 12 queries