PHP & MYSQL: using group by for categories

前端 未结 6 719
栀梦
栀梦 2020-12-08 08:54

My database has the following setup

productid | productname | category id

and I want to output them like so:

category #1
it         


        
6条回答
  •  情话喂你
    2020-12-08 09:30

    $stmt = $dbConnection->prepare("SELECT exam_id, COUNT(report_id) FROM bug_report GROUP BY exam_id; ");
            //$stmt->bind_param('s',$exam_id); 
            $stmt->execute();
            $extract = $stmt->get_result();
            $count = $extract->num_rows;
            if($count){
                while($rows = $extract->fetch_assoc()){
                    $exam_id = $rows["exam_id"];
                    switch($exam_id){
                        case "jee_questions":
                            $jeeBugCount = $rows["COUNT(report_id)"];
                            break;
                        case "gate_questions":
                            $gateBugCount = $rows["COUNT(report_id)"];
                            break;
                    }
                }   
            }
    

提交回复
热议问题