Jump to content

Search for a specific word in a text


Genius_cd

Recommended Posts

Hi,

 

well i am new here..

i'm kind not bad in php but im stuck @ this..

i have a mysql table with field description

 

table products

+---+----------------+

| ID |  description      |

+---+----------------+

|1  | Red                |

|2  | Liquered          |

|3  | Red,White        |

+---+----------------+

 

 

now i want to make a search with the term "red"

$sql = mysql_query("SELECT * FROM products WHERE description LIKE '%red%' ");

if i look inside the $sql the 3 rows are selected i want only the first and the last, how can i not integrate row 2 inside the sql search ??

the term red is inside Liquered , i dont want the sql (search) to select it ...

 

please any help??

Link to comment
https://forums.phpfreaks.com/topic/171760-search-for-a-specific-word-in-a-text/
Share on other sites

Hi,

 

well i am new here..

i'm kind not bad in php but im stuck @ this..

i have a mysql table with field description

 

table products

+---+----------------+

| ID |  description      |

+---+----------------+

|1  | Red                |

|2  | Liquered          |

|3  | Red,White        |

+---+----------------+

 

 

now i want to make a search with the term "red"

$sql = mysql_query("SELECT * FROM products WHERE description LIKE '%red%' ");

if i look inside the $sql the 3 rows are selected i want only the first and the last, how can i not integrate row 2 inside the sql search ??

the term red is inside Liquered , i dont want the sql (search) to select it ...

 

please any help??

 

ok and if i have redactive in row 4!!

 

Hi,

 

well i am new here..

i'm kind not bad in php but im stuck @ this..

i have a mysql table with field description

 

table products

+---+----------------+

| ID |  description      |

+---+----------------+

|1  | Red                |

|2  | Liquered          |

|3  | Red,White        |

|4  | redActive        |

+---+----------------+

You can use regular expressions in the query, to only select rows where red appear without bounding word characters (using word boundaries):

 

$sql = mysql_query("SELECT * FROM `products` WHERE `description` REGEXP '[[:<:]]red[[:>:]]'");

But I haven't actually seen that used before, so I'm not sure if it's inefficient or something.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.