0

列リストと配列を比較して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")
?>

どうすればいいですか?

4

2 に答える 2

0

これは IN 句で行うことができます。

SELECT * FROM <table> WHERE <col> IN <array>
于 2012-11-19T00:51:28.653 に答える
0

これを試して:

// 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})");

tablethe_letterをそれぞれテーブル名と列名に置き換えます。

于 2012-11-19T00:52:11.350 に答える