我想搜索MySQL数据库,将列列表与数组进行比较。我该如何做到这一点,可能都是在MySQL中?
下面是我想在PHP中做的事情:
<?php
$array = array("a", "b", "c", "d");
// 'c' doesn't exist in the database
$result = $this->mysqli->query("Query");
// Result should be array("a", "b", "d")
?>我该怎么做呢?
发布于 2012-11-19 08:51:29
您可以使用the IN clause来实现这一点。
SELECT * FROM <table> WHERE <col> IN <array>发布于 2012-11-19 08:52:11
试试这个:
// The array
$array = array("a", "b", "c", "d");
// This takes the array and puts it into a string like "a,b,c,d"
$array_for_query = implode(',', $array);
$result = $this->mysqli->query("SELECT * FROM table WHERE the_letter IN ({$array_for_query})");将table和the_letter分别替换为您的表名和列名。
https://stackoverflow.com/questions/13446269
复制相似问题