Only records with column containing x word appear

Asked

Viewed 46 times

0

I have a posting system done: the user posts and when the post contains a # followed by a word, the word is automatically added in another column with a comma. Post example:

Good #Personal @Stackoverflow Day, could you help me # ?

Example of record in table:

id: 1, post: Good #Personal @Stackoverflow Day, would you #help me ? , Author: Raphael, hashtags: day,help

Only that I am mounting a page to appear only posts containing hashtag x.

I need a code that shows only the records that contain the word x within the column hashtags.

Example: I need you to show all the records that contain the good word in the column hashtags.

id: 1, post: Could you help me #help, by the way, #good day! , Uthor: Raphael, hashtags: help,

id: 2, post: #Good evening @Stackoverflow staff, could you help me ? , Author: Raphael, hashtags: good, night,

id: 3, post: #Nice @Stackoverflow personal #fds, could you #help me ? , Author: Raphael, hashtags: good,fds,help

Then the system will show only the records with id 1 and 3 for containing the good word within the column hashtags.

  • Does this code help? $str = '#helloworld #test #video #youtube Bon Iver are the best Daily Surprise :D'; preg_match_all('/#([ s]+)/', $str, $Matches); $hashtags = implode(',', $Matches[1]); var_dump($hashtags);

  • Could you explain a little more how you want? I could not understand very well, leave examples if possible. See also [Ask]

  • @miltoncamara It is not to show the words without the # but to show the records that it contains within the column hashtags.

  • @Raphael, now understood, do you want to do this query in Mysql? Which bank are you using?

1 answer

2

To perform a search for a given word the wildcard character is used: % (Percentage)

To search the word, whether in the beginning, middle or end.

select * from NOMEDATABELA where hashtags like '%bom%'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.