2017-02-14 29 views
3

說明:陣列至字符串轉換在學說查詢注意:Array對字符串Converstion在Doctrain查詢

foreach($listLocations as $k=>$location){ 
    $list[] = "'".$location['id']."'"; 
} 

$storesList = implode(',', $list); //打印字符串(23)「 '191', '195',」 215' , '265'」

$storesList = (string)$storesList; 

我改成了字符串,但在查詢它仍在考慮爲陣

$sql="SELECT * from tbl_students WHERE s.store_id IN (".$storesList .")"; 
$conn = $this->getEntityManager()->getConnection();  
$stmt = $conn->prepare($sql); 

回答

3

首先改變$list[] = "'".$location['id']."'";

$list[] = $location['id']; 

現在做象下面這樣: -

$storesList = "('".implode("','", $list)."')"; 

而且

$sql="SELECT * from tbl_students WHERE s.store_id IN $storesList"; 

實例鏈接幫助: - https://eval.in/736486

+1

好和快回答。很好的例子。 – Deep

+0

@Deep thanks.Appreciate –

+1

感謝您的回答,但仍然遇到同樣的問題。 – Developer