php: Invalid Argument supplied

4185 views php
1

<?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>

I have use this code... but showing some error

error:

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

I want to get data from db... and then show all the photo... there is more than one data in db... and also there is file in the source folder... my problem is that i wanna show related photo if present else a website logo

answered question

Can you share the definition of getAllRows?

And while you are at it, print_r($student_info) after you run your getAllRows

1 Answer

3

Why not just wrap your foreach() with isset checking before doing any further looping with $student_infoarray ?

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

posted this

Have an answer?

JD

Please login first before posting an answer.