F
F
FLASH9112016-02-12 10:49:10
PHP
FLASH911, 2016-02-12 10:49:10

How to draw a conclusion from the MySql database of records that have a value in the enum string?

I have a MySQL table that contains records. One of the columns contains numbers separated by commas and spaces, for example: 1, 2, 3, 8, 12 in one entry and 2, 4, 5, 10 in another. It is necessary to display, for example, only those records that have a 1 in this column (in this example, the first one). Now LIKE is used, but in my opinion it is extremely irrational and puts a lot of load on the server. I would like to know how this can be implemented most correctly and without additional MySQL tables (required to be done to an existing database with a large number of records).
Now like this:

$variable1 = trim($value).",%";
$variable2 = trim($value);
$variable3 = "% ".trim($value).",%";
$variable4 = "% ".trim($value);
$where="pos LIKE '$variable1' or pos LIKE '$variable2' or pos LIKE '$variable3' or pos LIKE '$variable4'";
$query="SELECT * FROM  $post_m WHERE ( $where ) ORDER BY date_s DESC";

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey, 2016-02-12
@VladimirAndreev

FIND_IN_SET

K
Karl Meinhoff, 2016-02-12
@KarleKremen

This will be very uncomfortable and long. Get three tables: objects, values ​​and relationships. Each object and value has its own ID -> in the relation table objectID <-> valueID
UPD: guilty, I didn’t read about the extra. tables

R
res2001, 2016-02-12
@res2001

Under your conditions like - that's it.
According to the mind, you need to normalize the table as Karl Kremen suggests .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question