消息:为foreach()提供的参数无效[重复]

问题描述 投票:-3回答:1

这个问题在这里已有答案:

请帮助我是死胡同检查我的图片在视图codeigniter消息错误类别打开enter image description here

但对于类别结束和所有完成的工作没有错误;请帮忙

调节器

$limits=5;
$xx=$this->db->query('select * from posting')->row_array();
$x=$this->db->query('select * from kategori')->row_array();
in_array($x['kategori'],$dataArray=unserialize($xx['kategori'])) ?  $x['kategori']    : '' ;

foreach ($dataArray as $keys => $value) {
    if (($value == $link))  {
        $data['view']=$this->Cek_level->view6($limits,$link)->result();
    }
}

在视野中

<?php foreach($view as $row){?> 
php database codeigniter
1个回答
1
投票

您的代码只是做了很多假设,好像变量总是被设置并且是正确的类型。

$limits=5;

// First query
$xx = $this->db->query('select * from posting');

// Make sure you have a row before you try to use it.
if( $xx->num_rows() == 1 )
{
    $y = $xx->row_array();

    // Unserialize can always fail
    $dataArray = @unserialize( $y['kategori'] );
}

// Second query
$x = $this->db->query('select * from kategori');

// Make sure you have a row before you try to use it.
if( $x->num_rows() == 1 )
{
    $z = $x->row_array();
}

/*
It's impossible for me to know what you are trying to do here

in_array( $y['kategori'], $dataArray ) 
    ? $z['kategori'] 
    : '' ;
*/

// Make sure that dataArray is available as an array
if( isset( $dataArray) && is_array( $dataArray ) )
{
    foreach( $dataArray as $keys => $value )
    {
        // Make sure that $link exists
        if( isset( $link ) && $value == $link )
        {
            $data['view'] = $this->Cek_level->view6( $limits, $link )->result(); // Why not pass back the result ??
        }
    }
}

// Here we make sure view is available, no matter what happened
if( ! isset( $data['view'] ) )
    $data['view'] = [];

这段代码显然未经过测试,需要您进行更改才能使其正常工作,但会显示您需要检查数据和变量是否存在。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.