How does PHP query an SQL query that matches the value of a string and an array field? if it directly queries the records of pt = $ rpt, it is like this $ SQL = & quot; SELECT * FROM 'user' wherept = {$ rpt} & quot; now the pt field is an array. how does PHP query an SQL query that matches a string and a value in an array field?
If you directly query records with pt = $ rpt, this is the case.
$ SQL = "SELECT * FROM 'user' where pt = {$ rpt }";
The pt field is an array. for example, three records are
ID PT
1 aaaaa, bbbbb, ccccc, ddddd
2 www, zzz, vvv, qqq
3 ooo, pppp, lllll, ddd
Now, if rpt = ddd, I want to find out that there is a ddd record in PT, it should be the record with ID 3, that is, it exactly matches. Instead of 1, and 3.
How can I write this SQL statement?
------ Solution --------------------
',' + Pt + ', 'like' %, $ rpt, %'
------ Solution --------------------
... Where find_in_set ('$ rpt', pt)
------ Solution --------------------
I don't know, right ..
Try LZ?
PHP code
/* Based on the main data content * should be separated by a specific separator */$ SQL = "SELECT * FROM 'user' where pt = {$ rpt }"; $ result = mysql_query ($ SQL); while ($ row = mysql_fetch_array ($ result) {$ arr = explode (',', $ row ['pt']) foreach ($ arr as $ v) {if ($ v =={$ rpt}) {echo $ v ;}}}
------ Solution --------------------
Discussion
Reference:
... Where find_in_set ('$ rpt', pt)
This is not the case, as long as all the items including rpt match.
I want to find the exact match