PDO从输入日期和数组绑定php变量为WHERE IN

时间:2013-04-29 10:32:16

标签: arrays pdo execute implode

我是PHP / PDO的新手,所以请耐心等待。 我试图选择特定季节的房间价格,通过房间的Id。通过复选框选择房间。 (用户可以检查多个房间)Ids作为数组发送,日期从输入框发布。这是我的疑问:

$CheckInDate =   $_POST['CheckIn'];

$CheckOutDate   =  $_POST['CheckOut'];

$CheckInMonthDay = date("m-d",strtotime($CheckInDate));
$CheckOutMonthDay = date("m-d",strtotime($CheckOutDate));
$AptId = $_POST['CheckId'];//array of apartmentIds.

$placeholder = implode(',', array_fill(0, count($AptId),'?'));

$sth = $dbh->prepare("SELECT apartment_type.AptTypeId, AptType, People, Price_PerDay FROM    season
INNER JOIN price ON price.Season_Id = season.SeasonId
INNER JOIN apartment_type ON price.AptTypeId = apartment_type.AptTypeId
INNER JOIN apartment ON apartment.Apartment_typeId = apartment_type.AptTypeId
WHERE DATE_FORMAT( PeriodEnd, '%m-%d' ) >= ?
AND DATE_FORMAT( PeriodStart, '%m-%d' ) <= ?
AND AptId IN ($placeholder)");
$sth->bindParam(1,$CheckInMonthDay);
$sth->bindParam(2,$CheckOutMonthDay);

$sth->execute();

如何设法执行Checkin / CheckOut和Ids数组的变量?谢谢:))

0 个答案:

没有答案