im doing a system for school. and my problem was i cant display total student enrolled in each class. i can make a query in DB/ phpmyadmin for the data i need to be diplay. but for the hard code, its not working. can anyone help?
here's the body of my codes.
<?php
         $key="";
    if(isset($_POST['searchtxt']))
        $key=$_POST['searchtxt'];
    if($key !="")
        $sql_sel=mysql_query("SElECT * FROM class_tbl WHERE class_name  like '%$key%' ");
    else
            $sql_sel=mysql_query("SELECT * FROM class_tbl");
            $i=0;
    while($row=mysql_fetch_array($sql_sel)){
    $i++;
    $color=($i%2==0)?"lightblue":"white";
        ?>
      <tr bgcolor="<?php echo $color?>">
            <td><?php echo $i;?></td>
            <td><?php echo $row['class_name'];?></td>
            <td><?php echo $row['class_id'];?></td>
            <td><?php echo $row['class_year'];?></td>
            <td><?php
                    $result = mysql_query("SELECT class_name, COUNT( class_name ) FROM stu_tbl c GROUP BY class_name");
                    $num_rows = mysql_num_rows($result);
                    echo "$num_rows";
                    // $total_enrolled=mysql_query("SELECT COUNT( * ) FROM stu_tbl WHERE class_name =  'class_name'");
                    //echo $total_enrolled;
                ?>
if im using this codes, the output display will be 6 for all classes. which i think its the total number of class. not the student enrolled. the query i used in phpmyadmin works fine and its displayed the output i wanted to. thanks in advances for the helps. really appreciate it.
in phpmyadmin, im using this query, and its works fine.
SELECT class_name, COUNT( class_name ) FROM stu_tbl c GROUP BY class_name
i want the output to be display as :
no class_name  class_id  year  total_student_enrolled  
1   1 Amanah    1        2014   6       
2   1 Bestari   2        2014   2       
3   2 Amanah    9        2014   5       
4   2 Bestari   14       2014   10      
5   3 Amanah    15       2014   7       
6   3 Bestari   16       2014   1
total student enrolled will be count from student table which is based on the class_name in student table and how many student is associate with the class_name will be calculated as total_student_enrolled
 
     
     
    