我试图执行两个select语句,但它只显示第一个。我尝试使用foo->nextRowset();
但它不起作用,他停止向我显示第一个查询。我怎样才能获得2个查询的内容?我这样做是因为我需要在前端合并这些内容。
PHP:
<?php
header('Content-Type: application/json');
$dificuldade = $_GET ['dificuldade'];//Define a dificuldade das perguntas que seram selecionadas
$numquestions = $_GET ['rodada'];//Número de perguntas que serão retornadas
switch ($numquestions) {
case '1':
$numquestions = "10";
break;
case '2':
$numquestions = "15";
break;
case '3':
$numquestions = "20";
break;
}
try{
$conexao = new PDO ("mysql:host=localhost; dbname=teocratico; charset=utf8","root","");
} catch (PDOException $erro){
echo $erro->getmessage();
}
$stmt = $conexao->query ("SELECT
perguntas.id_pergunta,
perguntas.pergunta,
perguntas.resposta,
dificuldade.dificuldade
FROM perguntas
JOIN dificuldade
ON dificuldade.id_dificuldade = perguntas.dificuldade
WHERE dificuldade.id_dificuldade = $dificuldade limit $numquestions;
SELECT descricao from desafios ORDER BY RAND();
");
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($data, JSON_PRETTY_PRINT);
echo $json;
?>
答案 0 :(得分:1)
您需要单独执行每个语句:
select d.DirectoryName, d.DirectoryCount , f.Filename,f.FileNameCount from
(
select DirectoryName,
count(*)as DirectoryCount
from tblTable
group by DirectoryName
) as d
inner join
(
select DirectoryName, FileName,
count(*)as filenameCount
from tblTable
group by DirectoryName,FileName
) as f
on d.directoryName=f.DirectoryName
order by DirectoryName, FileName