PDO UNION SELECT结果不起作用

时间:2014-11-23 12:52:49

标签: php mysql pdo

下面的查询在PhPmyadmin中正常工作,结果有3行。但我无法将其纳入下面的变量(例如$ row [1] ....)

如何在PHP变量中获取UNION Select的结果?

$stmt = $pdo->prepare('
     (SELECT :items_per_pagina -COUNT(ID_opties) FROM table_a t1
     INNER JOIN table_2 t2 ON t2.ID = t1.ID
     INNER JOIN data_advertenties_geografie t3 ON t3.ID_advertentie = t1.ID_advertentie
     INNER JOIN htbl_plaatsnamen t4 ON t4.ID_plaatsnaam = t3.ID_advertentie
     WHERE 
     t2.status = 2 AND
     t2.ID_rubriek = :rubriek AND
     t1.regionaal_opvallen > UNIX_TIMESTAMP(NOW()) AND
     t4.ID_regio = (SELECT ID_regio FROM htbl_plaatsnamen WHERE ID_plaatsnaam = :plaatsnaam_id))
     UNION ALL (SELECT :items_per_pagina -COUNT(ID_opties) FROM table_a t1
     INNER JOIN table_2 t2 ON t2.ID = t1.ID
     WHERE 
     t2.status = 2 AND
     t2.ID_rubriek = :rubriek AND
     t1.landelijk_opvallen > UNIX_TIMESTAMP(NOW()))
     UNION ALL (SELECT :items_per_pagina -COUNT(ID_opties) FROM table_a t1
     INNER JOIN table_2 t2 ON t2.ID_advertentie = t1.ID_advertentie
     INNER JOIN htbl_rub ON htbl_rub.ID_rubriek = t2.ID_rubriek
     INNER JOIN htbl_categorien on htbl_categorien.ID_categorie = htbl_rubrieken.categorie
     WHERE 
     t2.status = 2
     AND htbl_categorien.ID_categorie = :categorie 
     AND t1.extra_opvallen > UNIX_TIMESTAMP(NOW()))
 ');
$stmt->bindParam(':items_per_pagina',$items_per_pagina, PDO::PARAM_INT);
$stmt->bindParam(':rubriek',$_GET['rubriek'], PDO::PARAM_INT);
$stmt->bindParam(':categorie',$_GET['categorie'], PDO::PARAM_INT);
$stmt->bindParam(':plaatsnaam_id',$_GET[':plaatsnaam_id'], PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_NUM);

$aantal_vrij_regionaal_opvallen = $row[0];
$aantal_vrij_landelijk_opvallen = $row[1];
$aantal_vrij_extra_opvallen = $row[2];

0 个答案:

没有答案