我有以下 MySQL 表
| module | module_id |
| 301 | 1 |
| 302 | 2 |
| 303 | 3 |
| 304 | 4 |
| 305 | 5 |
| 306 | 6 |
模块的名称以 JSON 数组的形式传递给 PHP。我想选择并显示数组中包含的所有模块 ID。例如,如果将模块 301、303 和 306 传递给脚本,我想返回值 1、3 和 6。
我整理了以下几乎可以工作的脚本,但不幸的是它只返回第一个值 - 所以如果数组中有 301、303 和 306,则脚本返回“1”,而不是 1、3 和 6。
我敢肯定,我可能缺少一些非常基本的东西,但无法弄清楚它是什么。有人可以帮忙吗?
谢谢!
$conn = (DATABASE CONNECTION INFO);
$modules = $_REQUEST['modules'];
$insertmodules = json_decode(stripslashes($modules), true);
$inmods = implode(',', $insertmodules);
$getmodsquery = "SELECT module_id FROM modules WHERE module IN ('$inmods')";
$getmods = $conn->query($getmodsquery);
while($row = $getmods->fetch_assoc()) {
foreach ($row as $value){
print_r($value);
}
}