Little white goes on. How to use an array as a condition for SQL query statements in PHP

Source: Internet
Author: User
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......
  • 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.