致命错误:在C:\ xampp中调用boolean上的成员函数fetch_assoc()

时间:2017-08-27 10:04:29

标签: php

我正在尝试根据他们的班级列出学生,当我选择班级名称并刷新表格时,它不会列出学生并给出致命错误

  

致命:在布尔值中调用成员函数fetch_assoc()   C:\ ... XAMPP

这是我编写的功能,我想根据他们的班级选择学生:

    function std_list_header(){

    $Connection=new mysqli("localhost","root","","dar_ul_hidaya");

    $query =" SELECT * FROM class";


        $res = mysqli_query($Connection, $query);

        if($res){
            $rs=mysqli_fetch_assoc($res);




            echo '<tr><td colspan="2" style="border-right:none;"><b>Class:'.$rs["jamat"].'</b></td>



            <td colspan="3" >
            <form action="student.php" method="POST">
            <select name="jamat">

<option value="-1">Select Class</option>';
$jamat=""; 
if (isset($_POST["jamat"])) {
    if($_POST["jamat"]>=0){
        $jamat=$_POST["jamat"]; 
    }
}


    $query="SELECT jamat FROM class";
    //echo $query; 
    $result=$Connection->query($query); 


    while($rs=$result->fetch_assoc()){

            echo"<option value=".$rs["id"]." ".($jamat==$rs["id"]?"selected":"").">".$rs["jamat"]."</option>";
    }
    echo '</select>
    <input type="submit" value="Refresh">
    </form>
                </td>


                </tr>';}


    }

这是我显示学生名单的主页:

<table align="center"  border="1px" width="600px">


<?php
        std_list_header();

?>



<tr>
    <th width="30px">کلاس</th>
    <th width="30px">ولدیت</th>
    <th width="30px">نام</th>
    <th width="30px">نمبر شمار</th>
</tr>



<?php

    $query="SELECT student.id ,student.name ,student.fname,student.class FROM  
student
inner join enroll on student.id=enroll.student_id 
inner join class on enroll.class_id=class.id"; 

if (isset($_POST["jamat"])) {
    if($_POST["jamat"]>=0){
$query=$query." where class.id=".$_POST["jamat"]; 

    }; 

}



$resultset=$Connection->query($query); 
$count=0; 
while($r=$resultset->fetch_assoc()){

    $count++; 
echo "

            <tr>

            <td>".$r["class"]."</td>
            <td>".$r["fname"]."</td>
            <td>".$r["name"]."</td>
            <td>".$count."</td>
            </tr>
"; 
}

?>



    </table>
</tr>
</table>

0 个答案:

没有答案