综合编程

The Foreach error variable can not be identified

微信扫一扫,分享到朋友圈

The Foreach error variable can not be identified
0

i have this function

function c_del()
{
    $session_data = $this->session->userdata('logged_in');
    $uname  = $session_data['username'];
    $query  = $this->user_m->viewDetail($uname);
    foreach($query as $row)
        {
            $username=$row->username;
        }
    $id_calon_reg=$_GET['a'];
    $query1 = $this->candidate_m->del_calon($id_calon_reg);
    $query3 = $this->candidate_m->search_calon($id_calon_reg);
    foreach($query3 as $row)
        {
            $foto_calon=$row->foto_calon;
        }
    unlink($foto_calon);
    $query2 = $this->candidate_m->viewAll();
    $data=array(
        "query"=>$query2,
        "username"=>$username
    );
    $this->load->helper(array('form'));
    $this->load->view('candidate_view',$data);
}

i want to unlink the path stored in $foto_calon, but i get this error

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: foto_calon
Filename: controllers/candidate.php
Line Number: 67

line 67 is where i call unlink function.

but I already define the variable $foto_calon in foreach.

the first foreach when i want to store the username into $username its success but got error in the second foreach.

i can’t find out what’s the problem. can anybody tell me?

Try to replace

foreach($query3 as $row)
{
   $foto_calon=$row->foto_calon;
}

with

if(is_array($query3)) {
    foreach($query3 as $row)
    {
        $foto_calon=$row['foto_calon'];
    }
}

And if you want to unlink each row
of foto_calon in the result array then put that unlink in this foreach loop like

if(is_array($query3)) {
    foreach($query3 as $row)
    {
        $foto_calon=$row['foto_calon'];
        unlink($foto_calon);
    }
}

阅读原文...


Hello, buddy!

12 most important pillars of an effective SEO strategy

上一篇

Openstack运维常见问题记录(3)

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
The Foreach error variable can not be identified

长按储存图像,分享给朋友