How does PHP query an SQL query that matches the values of a string and an array field?

Source: Internet
Author: User
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, this is the case for $ SQL & quot; SELECT * FROMuserwherept {$ rpt} & quot; now the pt field is an array. for example, there are three records: IDPT1aaaaa, bbbbb, ccccc, how does ddddd2www PHP query SQL queries that match the values of a string and 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.