Little White continued to ask for help. How to use an array as a condition for SQL query statements in PHP.
Small white Thank you greatly to their last post help, finally find out what is going on. Another problem is now encountered:
I have a page that allows the user to submit 12 multi-select lists,
Get Out is 12 arrays,
Then the database is searched based on the contents of these 12 arrays,
However, it seems that there is no way to extract the contents of these 12 arrays, and then write SQL query statements.
Like what:
$a = array (a,b,c,d);
$b = Array (1,2,3,4);
$c = Array (I,II,III,IV);
Then I want the 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
Do not know how to achieve it? In the case of a foreach loop, I'm afraid that every time the value of the current element is found, it is the result that every current element can search ...
But what I want to query is the final result of all the elements in the array that exist under the conditions:
Ask for help you tall man!
------Solution--------------------
Oh, so many and may find something?
PHP code
$a = Array (' A ', ' B ', ' C ', ' d '); $b = Array (1,2,3,4); $c = AR Ray (' I ', ' II ', ' III ', ' IV '); #保证 $a, $b, $c any non-empty array, judging by itself echo "SELECT * from table where Name= '". Implode ("' OR name= '", Array_merge ($a, $b, $c)). "'";
------Solution--------------------
at dinner, give you a hint
1 is the array of the output string implode (', ', $arr) punctuation and so on their own to process it again
1 is to modify your SQL statement Modify the same array and what into in
for example in (' A ', ' B ', ' C ', ' d ')
can
------solution--------------------
Discussion
Reference:
at dinner, give you a hint
1 is the array of the output string implode (', ', $arr) punctuation and so on their own processing it
1 is to modify your SQL The statement changes the same array and what into in
for example in (' A ', ' B ', ' C ', ' d ')
can
Thank you for your reply! If it is name in (' A ', ' B ', ' C ', ' d '), then it should be an or relationship?
Still is......