2015-09-04 139 views
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聲明懇求幫助

感謝名單

鮑勃

+0

您忘記了'ORDER BY postcode'後的結束報價 –

+3

是'$ stmt-> bindParam(':minPrice',$ _REQUEST ['minPrice']);'和'$ stmt-> bindParam(':maxPrice' ,$ _REQUEST ['maxPrice']);'不工作? –

+0

你有什麼問題嗎? – Jens

回答

-1

如何做準備的語句,涉及一BETWEEN語句

E中的查詢X爲C T Lý相同的方式與任何其它的查詢:通過添加必要的佔位符到查詢,然後通過使用bindParam方法結合它們。

+0

可能不是你的意圖,但它看起來像一個鈍的答案 – PerroVerd