How to display count data to Html using php codeigniter
P粉668113768
P粉668113768 2024-02-21 20:01:10
0
2
425

This is my model code:

public function GetId()
{
    $this->db->select('count(*) as total');
    $this->db->from($this->table);
    $this->db->where('dibaca', null);
    $query = $this->db->get();
    return $query->result_array();
}

This is my html code:

<?= $DataId['total']; ?>

I have called the function as DataId to my controller, I get the error, undefined array key 'total'

Can you tell me what's wrong?

P粉668113768
P粉668113768

reply all(2)
P粉842215006

Replace result_array() in the model with

num_rows()

You can remove ['total'] from the html code, or like this:

= $DataId; ?>
P粉210405394

Some untested suggestions:

Your model can be refined into:

public function countNullDibaca(): int
{
    return $this->db
        ->where("dibaca", null)
        ->count_all_results($this->table);
}

Your controller should call the model data and pass it to the view.

public function myController(): void
{
    $this->load->model('my_model', 'MyModel');
    $this->load->view(
        'my_view',
        ['total' => $this->MyModel->countNullDibaca()]
    );
}

Finally, your view can access the variables associated with the first-level keys in the passed array.

= $total; ?>

This is a related post that covers passing data from a controller to a view.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!