小白继续。PHP中怎么把数组作为sql查询语句的条件
小白继续求助。。PHP中如何把数组作为sql查询语句的条件。
小白感谢各位大大对于自己上一个帖子的帮助,终于弄明白是怎么回事了。 现在遇到了另一个问题:
我通过一个页面让用户提交了12个多选列表,
获取出来就是12个数组,
然后根据这12个数组里的内容进行数据库搜索,
可是发现好像没有办法把这12个数组里的内容一项一项提取出来,然后写sql查询语句。。
比如:
$a = array(a,b,c,d);
$b = array(1,2,3,4);
$c = array(I,II,III,IV);
然后我想select * from 表名 where name=a AND name=b AND name=c AND name=d AND name=1 AND name=2..... AND name=IV
不知道如何可以实现呢?用foreach循环的话,只怕每次都是当前元素的值,这样查出来是每一个当前元素可以搜索到的结果。。。
但是我想查询的是所有数组里所有元素存在的条件下,最后的结果。。
求助各位高人!
------解决方案--------------------
呵呵,那么多AND可能找到东西么?
- PHP code
$a = array('a','b','c','d'); $b = array(1,2,3,4); $c = array('I','II','III','IV'); #保证$a,$b,$c任意一个非空数组,自己判断 echo "select * from table where name='".implode("' OR name='",array_merge($a,$b,$c))."'"; <br><font color="#e78608">------解决方案--------------------</font><br> 在吃饭,给你提示<br>1个是将数组暑输出字符串 implode(',',$arr) 标点符号什么的自己再加工吧<br>1个是修改你的SQL 语句 将同个数组AND 什么的修改成 IN <br>例如 IN ('a','b','c','d')<br><br>即可 <br><font color="#e78608">------解决方案--------------------</font><br>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In PHP, we often need to combine elements in an array into a string. At this time, the implode() function comes in handy. The implode() function converts the elements in the array into strings and concatenates them to produce a complete string. This article will introduce how to use the implode() function in PHP to convert an array into a string. 1. Basic usage of implode() function The implode() function has two parameters. The first parameter

Title: Example of using the Array.Sort function to sort an array in C# Text: In C#, array is a commonly used data structure, and it is often necessary to sort the array. C# provides the Array class, which has the Sort method to conveniently sort arrays. This article will demonstrate how to use the Array.Sort function in C# to sort an array and provide specific code examples. First, we need to understand the basic usage of the Array.Sort function. Array.So

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

In PHP programming, Warning messages often appear. One of the more common prompts is "PHPWarning:implode():Invalidargumentspassed". This article will introduce the ideas and methods to solve this Warning. First, we need to understand how to use the implode() function. The function of this function is to concatenate an array into a string, using the following syntax: string

When programming in PHP, we often need to merge arrays. PHP provides the array_merge() function to complete array merging, but when the same key exists in the array, this function will overwrite the original value. In order to solve this problem, PHP also provides an array_merge_recursive() function in the language, which can merge arrays and retain the values of the same keys, making the program design more flexible. array_merge

In PHP, there are many powerful array functions that can make array operations more convenient and faster. When we need to combine two arrays into an associative array, we can use PHP's array_combine function to achieve this operation. This function is actually used to combine the keys of one array as the values of another array into a new associative array. Next, we will explain how to use the array_combine function in PHP to combine two arrays into an associative array. Learn about array_comb

In PHP programming, processing strings is a frequently required operation. Among them, splitting and merging strings are two common requirements. In order to perform these operations more conveniently, PHP provides two very practical functions, namely the explode and implode functions. This article will introduce the usage of these two functions, as well as some practical skills. 1. The explode function The explode function is used to split a string according to the specified delimiter and return an array. Its function prototype is as follows: arra

In PHP programming, the implode() function is a very commonly used function. This function is mainly used to concatenate elements in an array to form a string. The use of this function is very simple and flexible. It allows us to save time and code in the process of splicing strings. In this article, we will introduce PHP's implode() function in detail so that we can use it better. Basic syntax The basic syntax for using the implode() function in PHP is as follows: implode(separa
