-3

please help me is dead end Check my picture in view codeigniter message error in category opening enter image description here

but for category ending and all done work no error; please help

Controller

$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();
    }
}

in view

<?php foreach($view as $row){?> 
Brian Gottier
  • 4,522
  • 3
  • 21
  • 37
  • already tried not to work – Fathul Hudoyo Dec 26 '17 at 15:58
  • 1
    `var_dump($view)` what does it contain? – aynber Dec 26 '17 at 15:59
  • Already tried what? Those error messages are very informative. (BTW it is considered better practice to include the error message text directly in your post rather than linking to an image of text.) – faintsignal Dec 26 '17 at 16:00
  • @aynber C:\wamp64\www\blog\application\views\categories.php:136:null but in category Ending work C:\wamp64\www\blog\application\views\categories.php:136: array (size=3) 0 => object(stdClass)[23] public 'id' => string '2' (length=1) public 'pengunjung' => string '2' (length=1) public 'username' => string 'fathul' (length=6) public 'judul' => string 'Roys - Can’t you say (Single) Ending Koi to – Fathul Hudoyo Dec 26 '17 at 16:02
  • in database category opening already – Fathul Hudoyo Dec 26 '17 at 16:03
  • `if (($value == $link)) {` are you sure on this ?? – Abdulla Nilam Dec 26 '17 at 16:04
  • yes, I believe $link from public function categories($link) { } – Fathul Hudoyo Dec 26 '17 at 16:06

1 Answers1

1

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.

Brian Gottier
  • 4,522
  • 3
  • 21
  • 37
  • Indeed. Always assume that the array is empty and check via `num_rows()`. But you should really define your variables beforehand, like `$z = array()` because if the condition is never met it will be undefined. – Alex Dec 26 '17 at 19:40