For a unique mysql Query, you need to query the unique values of $ user in two columns of data.
For example, $ user = Pig
The following data indicates sixin
Id shuozhe tingzhe
1 pig
2 dogs and pig
3 NIU Ma
4 pig
The query result is 2, 4 (removed from irrelevant and duplicated pig)
However, my query statement will query 1, 2, 4, and solve. how can I only query 2, 4?
The query statement is as follows:
$ Str = "select distinct shuozhe, tingzhe from sixin where (shuozhe = '$ user' or tingzhe =' $ user') order by id desc"; // query? String
Reply to discussion (solution)
Remove or tingzhe = '$ user'
Search all the items first, and then compare them cyclically to remove unnecessary items.
Remove or tingzhe = '$ user'
If you remove or tingzhe = '$ user', there is a data shuozhe tingzhe
Cats and pigs
This item cannot be displayed. I want it to be displayed if it contains "pig ".
Search all the items first, and then compare them cyclically to remove unnecessary items.
I don't quite understand this, but I want to say something specific.
$ Str = "select shuozhe, tingzhe from sixin where (shuozhe = '$ user' or tingzhe =' $ user') group by shuozhe, tingzhe order by id desc "; // query? String
$ Str = "select shuozhe, tingzhe from sixin where (shuozhe = '$ user' or tingzhe =' $ user') group by shuozhe, tingzhe order by id desc "; // query? String
The results are repeated, that is, the pigs, dogs, and dogs will be searched together.
Guidance ,,,,,,,,,,,,,
We recommend that you retrieve all the pigs with the two fields and make a judgment in php. you need to determine that the intersection of the two fields is equal. mysql is not easy to handle.