C
C
Caspergreen2015-12-02 20:12:10
MySQL
Caspergreen, 2015-12-02 20:12:10

Checking data from one table to another CodeIgniter. How?

There is a function, in it there is a selection from the database, there is a field in the table, section.
This field stores the ID of data from another table.
The sections table stores sections.
On the page, the data, title, picture and section title are displayed. I'm looking for a section by id.
For example, in the bouquets table in the section id field, 1 is indicated, then the table is searched by id, then the name of this section is twitched.
If the section is deleted, and the bouquet has ID 1, then it starts swearing with the
Severity: Notice

Message: Trying to get property of non-object

Filename: bouquets/index.php

Line Number: 90

Line:
echo $sections->title;
Controller:
if($this->data['list'] == 0){
            $this->session->set_flashdata('null', 'Записей в базе данных не сущестует.');
        } else {
            //print_r($this->data['list']);
            foreach($this->data['list'] as $value){
                    $list_id =  $value->section;
                }
                $this->data['sections'] = $this->bouquets->getSectionID($list_id);
        }

Model:
function getSectionID($list_id){
        $this->db->where('id', int() $list_id);
        $this->db->limit(1);
        $query = $this->db->get('sections');
        $rows = $query->result();
        return isset($rows[0] ? $rows[0] : false);
    }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Smirnov, 2015-12-04
@Caspergreen

foreach($this->data['list'] as $value){
                    $list_id =  $value->section;
                }
                $this->data['sections'] = $this->bouquets->getSectionID($list_id);

This part is not clear at all. Firstly, the data structure in $this->data['list'] is not clear, probably there is an array of values ​​from another model. But then why are you referring to them like this: $value->section and not $value['section']. Secondly, why do this senseless enumeration in a loop?

C
Caspergreen, 2015-12-02
@Caspergreen

Severity: Notice

Message: Trying to get property of non-object

Filename: bouquets/index.php

Line Number: 97

Same note :)

R
repeat, 2015-12-03
@repeat

Is $sections an object or an array? You are trying to work with it as an object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question