2017-02-14 1 views
3

Hinweis: Array in String-Umwandlung in Lehre AbfrageHinweis: Array String converstion in Doctrain Abfrage

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

$storesList = implode(',', $list); // Gibt string (23) " '191', '195',‘ 215' , '265'“

$storesList = (string)$storesList; 

ich es String geändert, aber in Query bedenkt, dass es immer noch als Array

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

Antwort

3

Zu allererster Änderung $list[] = "'".$location['id']."'"; zu

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

Jetzt tut unten wie: -

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

Und

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

Beispiel Links für die Hilfe: - https://eval.in/736486

+1

nett und schnell Antworten. gut Beispiel. – Deep

+0

@Deep thanks.Preciate dass –

+1

Danke für die Antwort, aber ich bin immer noch auf das gleiche Problem. – Developer

Verwandte Themen