Your code is just making a lot of assumptions, as if the variables will always be set and be the right type.
$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'] = [];
This code is obviously untested, and will need to be altered by you to make it work, but shows how you need to be checking if data and variables exist.