0

I want to get num_rows of query but i need to get it from result_array not from query. So, i call function array_sum to calculate num_rows but it doesnt work

I've tried to using array_sum (php function) but it return 0, it supposed to return 3

ListModel.php

Class ListModel extends CI_Model {
    public function getList($id=null){
        $listm = $this->db->query("
                    SELECT * FROM m_list m
                    LEFT JOIN list_country lc ON lc.id=m.id_country
                    WHERE lc.id_section = $id"
        )->result_array();
        return $listm;
    }
}

MController.php

$arr_m= $this->ListModel->getList(15);

$return['total'] = array_sum($arr_m);

any idea to solved it?

0

2 Answers 2

1

You need to use count or sizeof function for get length of array.

$return['total'] = count($arr_m);
Sign up to request clarification or add additional context in comments.

Comments

0

Missing closing double quotes

Class ListModel extends CI_Model {
        public function getList($id=null){
            $listm = $this->db->query("
                        SELECT * FROM m_list m
                        LEFT JOIN list_country lc ON lc.id=m.id_country
                        WHERE lc.id_section = $id
            ")->result_array();
            return $listm;
        }
    }

1 Comment

sorry i forget to copy that. the list is fine and return 3 array that i need, the problem is i need total but it return 0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.