Connecting Tech Pros Worldwide Help | Site Map

Searching all fields at once

Familiar Sight
 
Join Date: Sep 2007
Posts: 210
#1: 3 Weeks Ago
Hi everyone
I was wondering if it's possible to search all fields of a table at once.

Let's say we have a table called (articles) :

Expand|Select|Wrap|Line Numbers
  1. + ID +   Name   + Description  +
  2. | 1  | computer | AMD Athlon   |
  3. | 2  | table    | Black painted|
  4. | 3  | Chair    | Orange       |
  5.  
Then we have a search box which allows users to serach.

Is it possible to serach in both filds (Name , Description) at the same time.
Something like this:

Search text = table painted

Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM articles WHERE * LIKE '%table%painted%'"
  2.  
The result should be the second row.

Thanks
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: 3 Weeks Ago

re: Searching all fields at once


You can use the AND operator to extend your WHERE clause.

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM `articles` WHERE `Name` LIKE '%table%' AND `Description` LIKE `%painted%`;
  2.  
Mark.
Familiar Sight
 
Join Date: Sep 2007
Posts: 210
#3: 3 Weeks Ago

re: Searching all fields at once


Thanks Markus for the reply
It's what i'm doing right now. But I was thinking if it's possible to search the whole row without naming each field.

Like this

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM articles WHERE (whole row) LIKE "%table%"
  2.  
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#4: 3 Weeks Ago

re: Searching all fields at once


Quote:

Originally Posted by bnashenas1984 View Post

Thanks Markus for the reply
It's what i'm doing right now. But I was thinking if it's possible to search the whole row without naming each field.

Like this

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM articles WHERE (whole row) LIKE "%table%"
  2.  

Not that I know of.

Mark.
Reply