나는 그 점수를 기반으로 데이터베이스에서 학생 수를 얻으려고합니다. 내가 사용하는 다른 마크와 학생의 수를 얻기 위해 COUNT (*)를 사용하고 있습니다 :COUNT에서 전체 번호를 가져올 수 없습니다.
SELECT COUNT(*) FROM marks WHERE totalmarks >=21 AND totalmarks <=30
그것은 마크 (21) 사이 30 내 데이터베이스의 SQL 학생의 수를 표시 할 수 있습니다.
<?php
require("config1.php");
$query="SELECT COUNT(*) FROM marks WHERE totalmarks >=21 AND totalmarks <=30";
try {
$stmt = $db->prepare($query);
$result = $stmt->execute();
}catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error!";
die(json_encode($response));
}
$rows = $stmt->fetchAll();
if ($rows){
$response["success"]=1;
$response["message"]="No of student";
$response["count"]=count($rows);
array_push($response["count"]);
echo json_encode($response);
}else {
$response["success"] = 0;
$response["message"] = "No Available!";
die(json_encode($response));
}
?>
결과는 {"success":1,"message":"No of student","count":1}
입니다 가 잘하여 4 명 학생이어야한다, 단 1을 보여줍니다 내 PHP 코딩에 시도하지만 수를 표시 할 수 없습니다, 이건 내 코드입니다. 누군가가이 문제를 해결할 수 있다면 감사하게 생각합니다.
Array
(
[0] => Array
(
[count(*)] => 4
[0] => 4
)
)
지금 다시 count
를 호출이 시간 : enter image description here
이이 부분을 해결하고 작동해야 문제는 있지만 문제의 해결책은 아닙니다. 솔루션으로 수정하십시오. –
내가 무엇을 놓쳤는가? – mrks