从MySQL表WHERE字段='$阵'选择? [英] Select from mysql table WHERE field='$array'?

查看:232
本文介绍了从MySQL表WHERE字段='$阵'选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有发言权的数组,有的ID用户的。我怎么会做这样的事情:

If I have an array of say, some ID's of users. How could i do something like this:

$array = array(1,40,20,55,29,48);
$sql = "SELECT * FROM `myTable` WHERE `myField`='$array'";

有一个简单的方法来做到这一点,我想到了通过数组项循环,然后建立一个大的WHERE - 或 - 或者 - OR语句,但我认为这可能是大型阵列有点慢

Is there a simple way to do this, I thought about looping through array items and then building up one big "WHERE -- OR -- OR -- OR" statement but i thought that might be a bit slow for large arrays.

推荐答案

使用

$sql = "SELECT * FROM `myTable` WHERE `myField` IN (1,40,20,55,29,48)";

您可以使用破灭(,$阵列)从数组一起获取列表。

you can use implode(",", $array) to get the list together from the array.

这篇关于从MySQL表WHERE字段='$阵'选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆