Как исправить ошибку при поиске на сайте?

0
я сделал модель поиска для трех таблиц так:
<?php

class Search_model extends CI_Model {

    public function search($q) {
        $array_search = array(
            'name' => $q,
            'descriptions' => $q
        );

        $query1 = $this->db
            ->or_like($array_search)
            ->limit(100)
            ->get('movie');

        $query2 = $this->db
            ->or_like($array_search)
            ->limit(100)
            ->get('serial');

        $query3 = $this->db
            ->or_like($array_search)
            ->limit(100)
            ->get('animation');

        return [
            'movie' => $query1->result_array(),
            'serial' => $query2->result_array(),
            'animation' => $query3->result_array(),
        ];

        
    }

}

а это контроллер:
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Search extends MY_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $this->data['title'] = "Search";

        $this->load->model('search_model');
        $this->data['search_result'] = array();

        if($this->input->get('q_search')) {
            $this->data['search_result'] = $this->search_model->search($this->input->get('q_search'));
        }


        $this->load->view('templates/header', $this->data);
        $this->load->view('search', $this->data);
        $this->load->view('templates/footer');
    }
}

а это view//search.php
<h2>Search (Result <?php echo count($search_result); ?>)</h2>

<?php foreach($search_result as $key => $value): ?>

    <div class="well">
         <a href="/movies/view/<?php echo $value['slug']; ?>"><?php echo $value['name']; ?></a> <br> <?php echo $value['descriptions']; ?>
    </div>

    


<?php endforeach ?>

когда я ищу на сайте фильм или сериал мне выдает три ошибки
1
A PHP Error was encountered
Severity: Notice

Message: Undefined index: slug

Filename: views/search.php

Line Number: 6

Backtrace:

File: C:\xampp\htdocs\movieworld\application\views\search.php
Line: 6
Function: _error_handler

File: C:\xampp\htdocs\movieworld\application\controllers\Search.php
Line: 23
Function: view

File: C:\xampp\htdocs\movieworld\index.php
Line: 315
Function: require_once

2:
A PHP Error was encountered
Severity: Notice

Message: Undefined index: name

Filename: views/search.php

Line Number: 6

Backtrace:

File: C:\xampp\htdocs\movieworld\application\views\search.php
Line: 6
Function: _error_handler

File: C:\xampp\htdocs\movieworld\application\controllers\Search.php
Line: 23
Function: view

File: C:\xampp\htdocs\movieworld\index.php
Line: 315
Function: require_once

3:
A PHP Error was encountered
Severity: Notice

Message: Undefined index: descriptions

Filename: views/search.php

Line Number: 6

Backtrace:

File: C:\xampp\htdocs\movieworld\application\views\search.php
Line: 6
Function: _error_handler

File: C:\xampp\htdocs\movieworld\application\controllers\Search.php
Line: 23
Function: view

File: C:\xampp\htdocs\movieworld\index.php
Line: 315
Function: require_once

как исправить? что я сделал неправильно?
codeigniter

2 ответов

0

подписал ниже как сказал теперь сверху выдаете результат

сделал так как ты сказал,подписал ниже и теперь сверху выдает результат
array(3) { ["movie"]=> array(1) { [0]=> array(11) { ["id"]=> string(3) "861" ["slug"]=> string(8) "13-hours" ["name"]=> string(8) "13 Hours" ["director"]=> string(11) "Michael Bay" ["descriptions"]=> string(103) "During an attack on a U.S. compound in Libya, a security team struggles to make sense out of the chaos." ["year"]=> string(4) "2016" ["rating"]=> string(3) "7.3" ["poster"]=> string(94) "https://static.imovies.cc/movies/posters/240/58/450148058-cc1843a997480613ca3b67a05e55892a.jpg" ["player_code"]=> string(60) "https://api.imovies.cc/api/v1/movies/450148058/files/1237060" ["add_date"]=> string(19) "2020-11-22 23:16:31" ["category_id"]=> string(1) "1" } } ["serial"]=> array(0) { } ["animation"]=> array(0) { } }

а на главной странице все теже ошибки
1
A PHP Error was encountered
Severity: Notice

Message: Undefined index: slug

Filename: views/search.php

Line Number: 6

Backtrace:

File: C:\xampp\htdocs\movieworld\application\views\search.php
Line: 6
Function: _error_handler

File: C:\xampp\htdocs\movieworld\application\controllers\Search.php
Line: 24
Function: view

File: C:\xampp\htdocs\movieworld\index.php
Line: 315
Function: require_once

2
A PHP Error was encountered
Severity: Notice

Message: Undefined index: name

Filename: views/search.php

Line Number: 6

Backtrace:

File: C:\xampp\htdocs\movieworld\application\views\search.php
Line: 6
Function: _error_handler

File: C:\xampp\htdocs\movieworld\application\controllers\Search.php
Line: 24
Function: view

File: C:\xampp\htdocs\movieworld\index.php
Line: 315
Function: require_once

3
A PHP Error was encountered
Severity: Notice

Message: Undefined index: descriptions

Filename: views/search.php

Line Number: 6

Backtrace:

File: C:\xampp\htdocs\movieworld\application\views\search.php
Line: 6
Function: _error_handler

File: C:\xampp\htdocs\movieworld\application\controllers\Search.php
Line: 24
Function: view

File: C:\xampp\htdocs\movieworld\index.php
Line: 315
Function: require_once
0
Undefined index: slug
Undefined index: name
Undefined index: descriptions

Эти ошибки говорят о том, что нету в массивах, которые получены из базы данных таких ключей, по которым обращаешься к ним. Напиши в контроллере после строчки:

$this->data['search_result'] = $this->search_model->search($this->input->get('q_search'));
// Это написать:
echo var_dump($this->data['search_result']);

и посмотри, какие данные получил из базы данных и есть ли там вообще эти ключи массива к которым обращаешься. 

Sign up or Log in to write an answer