1

This is my query counting rows in tblapplication

public function countallrecord() {
    $query = $this->db->get('tblapplication');

    return $query->num_rows();  
}

and this is the function to get all the data

public function getdata() {
    $query = $this->db->get('tblapplication');

    return $query->result();
}

Is there any way I can make this code on one function

I'm trying to pass it here:

public function Countandviewallrecord() {
    // returns both rows and count
}

2 Answers 2

1

Just return it as an array. Include the results and count in their respective indices:

public function get_records()
{
    $result = $this->db->get('tblapplication');
    $data['results'] = $result->result();
    $data['count'] = $result->num_rows;

    return $data;
}

When accessing the model method in your controller, the usual:

$data = $this->model_name->get_records();

echo $data['count']; // whatever number this is
if($data['count'] > 0) {
    foreach($data['results'] as $row) {
        echo $row->column_name; // etc blah blah ..
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you this is what im looking!
0

this Countandviewallrecord will display data as well count total records

public function Countandviewallrecord(){

$TotalRecords= $this->countallrecord();
$totalData= $this->getdata();

    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.