0

i have problem to show my query result in my view, i user codeigniter with mvc structure, in model my code its look like this,

<?php
class Model_Kabalitbang extends CI_Model{

    public function getPaguAnggaran(){
        $query  = "SELECT pagu_anggaran_program_modalutama FROM program_modal_utama WHERE id_program_modalutama = '3'
                  ";
        return $this->db->query($query);      
    }
}

and in my controller i call my model like this

<?php
class Kabalitbang extends CI_Controller{
  function __construct(){
    parent::__construct();
    if($this->session->userdata('logged_in') !== TRUE){
      redirect('login');
    }

    $this->load->model('Model_Kabalitbang');
  }

  function index(){
    //Allowing akses to kabalitbang only
    if($this->session->userdata('level')==='2'){
      // Jumlah PAGU
        $pagu            = $this->Model_Kabalitbang->getPaguAnggaran();
        $paguanggaran    = $pagu->num_rows();

        $data = array(
            'jml_pagu'      => $paguanggaran,
        );
      $this->load->view('kabalitbang/dashboard_view', $data);
    }else{
        echo "Access Denied";
    }

  }

}

but when i call in view <?=$jml_pagu ?> this show just 1, but the value form field in my query is 24392 this is my result query

how to make my code run?

3
  • can you confirm that running the SELECT pagu_anggaran_program_modalutama FROM program_modal_utama WHERE id_program_modalutama = '3' query returns 24392 rows? Commented Nov 17, 2019 at 6:45
  • yes when i try run my query, the result is 243929203000 Commented Nov 17, 2019 at 6:48
  • @HastaDhana i already updated my question, thank you for help me Commented Nov 17, 2019 at 6:52

2 Answers 2

1

Your query is already return a row containing a number, so you just need to display the row, not counting the row again :

        $pagu            = $this->Model_Kabalitbang->getPaguAnggaran();
        $paguanggaran    = $pagu->row_array();

        $data = array(
            'jml_pagu'      => $paguanggaran['pagu_anggaran_program_modalutama'],
        );
Sign up to request clarification or add additional context in comments.

Comments

1

use this...

$this->db->where('id_program_modalutama ',3);
$result['data']=$this->db->get('Table Name')->result();
$this->load->view('kabalitbang/dashboard_view', $result);

now use loop on $data in your view... Example :-

foreach($data as $allData)
{
print_r($allData);
}

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.