在php中以mysql的表格显示组

I have a query in mysql which will return a table grouped by some fields. How can I echo these results? Here is piece of my code.

$stmt = $con->prepare("
SELECT classSubject
     , COUNT(*) cnt
  from Class 
 where grade=? 
   and department=? 
   and classGroup IN(?,3) 
 GROUP 
    BY classSubject;
");
    $stmt->bind_param("isi", $grade, $department, $classGroup);

 //executing the query 
 $stmt->execute();

What should I do after this so that I can echo all the result?

After reading Tim Biegeleisen's answer and doing a bit of surfing, I came up with this solution. After executing the query:

$response = array(); 
 $response['success']=true; 

    $stmt->bind_result($classSubject,$cnt);

    while ($stmt->fetch()) 
    {
        $response[$classSubject]=$cnt;
    }

 echo json_encode($response);

Hope this helps someone.

I recommend reviewing a good site which can serve as an example of what syntax to use, such as this one.

$sql = "SELECT classSubject, COUNT(*) cnt FROM Class ";
$sql .= "WHERE grade = ? AND department = ? AND (classGroup = ? OR classGroup = 3) ";
$sql .= "GROUP BY classSubject";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("isi", $grade, $department, $classGroup);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        echo "(classSubject, count) = (" . $row['classSubject'] . ", " . $row['cnt'] . ")";
    }
}

Note that I add an alias to the COUNT(*) term in the select so that we can easily refer to it by name in PHP. You could also just refer to columns using their numeric indices, but going by name is an easier and safer way to do it.