Welcome Guest, Not a member yet? Register   Sign In
how to display count_all_results record to view
#1

Hi I am having trouble echoing a count to my view.

Please help. I am trying to count the number of subjects in the database.

Model:

PHP Code:
  public function Gettotsubjects($session_id$section_id$class_id
    {
        $this->db->select('subject_id');
        $this->db->where('session_id'$session_id);
        $this->db->where('section_id'$section_id);
        $this->db->where('class_id'$class_id);
        $this->db->distinct();
        return $this->db->count_all_results('ftscores_primary');
    

Controller:


PHP Code:
  public function Gettotsubjects($session_id$section_id$class_id)
     {
    $data $this->ftprimary_model->Gettotsubjects($session_id$section_id$class_id); 
    return $data->subject_id;
         
    


View:

PHP Code:
<?php echo $CI->Gettotsubjects($value->session_id$value->section_id$value->class_id);?>

Nothing shows in the view even though it works well when I test in the Controller
Reply
#2

@EseMiami,

What version of CI are you using (3.x or 4.x)?
Reply
#3

(12-15-2020, 02:02 PM)php_rocs Wrote: @EseMiami,

What version of CI are you using (3.x or 4.x)?

I'm using CI_VERSION = '3.1.6'
Reply
#4

I'm sorry but your code doesn't make a lot of sense. The model return count_all_results but the controller return subject_id???
Also, instead of the controller displaying the view, it's the other way around and your view is calling your controller?
There must be missing code you have not post...
Or maybe what you call a controller is a library, but still, you return the count and display the id...
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB