Tonza Tonza - 4 months ago 8
SQL Question

Search from mysql column

I Have a post from where you can select which category your post will belong to.
You can select max 5 different category (tags).

It saves these tags to same column to mysql.

id user title body tags Date
1 Tony Functions .... javascript,jquery,html,mysql 2016-07-27





id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
user TEXT,
title TEXT,
body TEXT,
tags TEXT,
date DATE,


If user search for javascript posts it should show all posts that have javascript tag included to tag column.

How do I make the mysql select with PHP?

Answer

You use a wildcard search...

SELECT * FROM `table` WHERE `tags` LIKE '%javascript%'

But you may want to reconsider your table layout, making it more normal.

Comments