Tom continues to seek help .. In PHP, how does one use arrays as conditions for SQL query statements. Thank you for your great help in your previous post and finally figured out what was going on. Now I encountered another problem: I asked the user to submit 12 multi-choice lists on one page, and obtained 12 Arrays. then I searched the database based on the contents of these 12 groups, however, it seems that there is no way to extract the content from these 12 groups one by one and then write SQL query statements .. For example, $ .. In PHP, how does one use arrays as conditions for SQL query statements.
Thank you for your great help in your previous post and finally figured out what was going on. Another problem is encountered:
On a page, I asked the user to submit 12 multi-choice lists,
12 arrays are obtained,
Then, the database is searched based on the content of the 12 groups,
However, it seems that there is no way to extract the content from these 12 groups one by one and then write SQL query statements ..
For example:
$ A = array (a, B, c, d );
$ B = array (1, 2, 4 );
$ C = array (I, II, III, IV );
Then I want to select * from table name where name = a AND name = B AND name = c AND name = d AND name = 1 AND name = 2 ..... AND name = IV
I don't know how to implement it? If you use a foreach loop, you are afraid that each time it is the value of the current element. in this way, you can find the result that can be searched by each current element...
However, I want to query the final result when all elements in all arrays exist ..
Help everyone!
------ Solution --------------------
Oh, so many AND may find something?
PHP code
$ A = array ('A', 'B', 'C', 'D'); $ B = array (1, 2, 3, 4 ); $ c = array ('I', 'II', 'II', 'IV '); # ensure that any non-empty array of $ a, $ B, $ c, echo "select * from table where name = '". implode ("'OR name ='", array_merge ($ a, $ B, $ c )). "'";
------ Solution --------------------
At dinner, please remind me
One is to output the array heat output string implode (',', $ arr) punctuation marks or something, and then process it by yourself.
One is to modify your SQL statement to change the same array AND or something to IN.
For example, IN ('A', 'B', 'C', 'D ')
You can.
------ Solution --------------------
Discussion
Reference:
At dinner, please remind me
One is to output the array heat output string implode (',', $ arr) punctuation marks or something, and then process it by yourself.
One is to modify your SQL statement to change the same array AND or something to IN.
For example, IN ('A', 'B', 'C', 'D ')
You can.
Thank you for your reply! If it is name IN ('A', 'B', 'C', 'D'), should it be an OR relationship? Or ......