|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello,
Is it possible to search in multiple columns (in one table or even better the whole database) for a string pattern, without specifying al the columnnames? Regards, Daan |
|
#2
|
|||
|
|||
|
Nope.
|
|
#3
|
||||
|
||||
|
Well, you kind of can, but I don't think it's a very good way to do it. You should think about re-organizing your database to make searching better.
SELECT * FROM your_table WHERE CONCAT(column1,column2,column3...) like '%$your_variable%'; It basically takes the columns and joins them together in one string, then searches for your variable. The % signs mean your string can be preceded and followed by anything. An option I'd recommend is to write another script that searches your table columns and extracts all the words, then stores the words in another table with an ID back to the record it came out of. Then you do your searches on this table, return the IDs that match the word, and look up those IDs in your main table. You can index this second table to make searches pretty fast. My $0.02. ---John Holmes... ------------------ ************************************************************* * The manual can probably answer 90% of your questions... * * * * PHP Manual. www.php.net/manual * * MySQL Manual: www.mysql.com/documentation/mysql/bychapter * ************************************************************* |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > pattern matching in multiple columns |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|