php:提供了无效的参数

时间:2018-09-15 15:49:33

标签: php

<?php 
    $student_info = getAllRows('student');
    $counter = 1;
    foreach ($student_info as $key => $student) {
?>
<tr>
    <td><?php echo $student['email']; ?></td>
    <td>
    <?php 
        if (isset($student['image']) && !empty($student['image']) && file_exists(UPLOAD_DIR.'student/'.$student['image'])) {
            echo "<img src='upload/student/".$student_info['image']."' class='img img-responsive img-thumbnail' width='300px'> ";
        }else{
            echo "<img src='upload/logo.png' class='img img-responsive img-thumbnail' width='300px'> ";
        }
    ?>
    </td>
    <td><a href="addaccount.php?id=<?php echo $student['id'] ?>&amp;act=edit">edit</a>/<a href="account.php?id=<?php echo $student['id'] ?>&amp;act=delete" onclick="return confirm('Are You sure you want to delete this student Account?');">delete</a>/<a href="change_password.php?id=<?php echo $student['id'] ?>&amp;act=change_password">Change Password</a></td>
</tr>

我已经使用了这段代码...但是显示了一些错误

错误:

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\school\admin\view_student_profile.php on line 58

我想从db中获取数据...然后显示所有照片... db中有多个数据...并且源文件夹中也有文件... 我的问题是,如果要显示其他徽标,我想显示相关照片

1 个答案:

答案 0 :(得分:1)

在使用foreach($student_info)数组进行任何进一步循环之前,为什么不只用!empty($student_info)来包装$student_info呢?

if(!empty(student_info)){
    foreach ($student_info as $key => $student) {
     // your other code goes here 
    }
}