我正在尝试在MySQL查询的where子句中使用数组,但查询未正确显示发布的数组。
我发布阵列,控制台显示:
[RoomOverrideRoomSelect] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
然后我像这样处理数组:
$MultiRoomID = $_POST['RoomOverrideRoomSelect'];
$arr_Rooms = array($MultiRoomID);
$str_Rooms=implode(",", $arr_Rooms);
我的查询:
"SELECT
RecordID, ConfRoomID, ConfRoomName
FROM ConfRooms2017
WHERE HotelID = '". $_SESSION['hotelid']. "'
AND ConfRoomID IN ('$str_Rooms')";
如果我回显查询,我将得到:
SELECT
RecordID, ConfRoomID, ConfRoomName
FROM ConfRooms2017
WHERE HotelID = 'EXBHX'
AND ConfRoomID IN ('Array')
应该是:
SELECT
RecordID, ConfRoomID, ConfRoomName
FROM ConfRooms2017
WHERE HotelID = 'EXBHX'
AND ConfRoomID IN (1,2,3)
谁能看到我要去哪里错了?