0
我是相當新的使用PDO,現在有涉及BETWEEN聲明並不能看到怎麼辦準備的語句進行這樣的查詢 - 這裏是代碼的MySQL與PDO BETWEEN準備語句
try {
include("../epsadmin/connectpdo.php");
$sql="SELECT * FROM properties
WHERE location LIKE :location
AND bedrooms LIKE :bedrooms
AND category LIKE :category
AND price BETWEEN :minPrice and :maxPrice
ORDER BY postcode";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':location', $_REQUEST['location'], PDO::STR);
$stmt->bindParam(':bedrooms', $_REQUEST['bedrooms'], PDO::STR);
$stmt->bindParam(':category', $_REQUEST['category'], PDO::STR);
//bindParam for price BETWEEN minPrice and MaxPrice needed
$stmt->execute();
$total = $stmt->rowCount();
$obj = $stmt->fetchObject();
}//end try
catch(PDOException $error) {
$send='DB Query failed: ' . $error->getMessage();
header("Content-type: text/plain");
echo $send;
exit;
}
莫非有誰請與所需的bindParam聲明懇求幫助
感謝名單
鮑勃
您忘記了'ORDER BY postcode'後的結束報價 –
是'$ stmt-> bindParam(':minPrice',$ _REQUEST ['minPrice']);'和'$ stmt-> bindParam(':maxPrice' ,$ _REQUEST ['maxPrice']);'不工作? –
你有什麼問題嗎? – Jens