0

i don't really understand what happen there. I got problem at line 87

$this->data['option_pengujian'][$row->id_penguji] = $row->penguji;

this is the code of the function

public function tambah()
    {
        $this->data['breadcrumb']   = 'Pengujian > Tambah';
        $this->data['main_view']    = 'view_pengujian/pengujian_form';
        $this->data['form_action']  = 'pengujian/tambah';
        $penguji = $this->penguji->cari_semua();
        if($penguji)
        {
            foreach($penguji as $row)
            {
                $this->data['option_pengujian'][$row->id_penguji] = $row->penguji;
            }
        }
        else
        {
            $this->data['option_pengujian']['00'] = '-';
            $this->data['pesan'] = 'Data penguji tidak tersedia. Silahkan isi dahulu data penguji.';
            // if submit
            if($this->input->post('submit'))
            {
                if($this->siswa->validasi_tambah())
                {
                    if($this->siswa->tambah())
                    {
                        $this->session->set_flashdata('pesan', ' Proses tambah data berhasil');
                        redirect('pengujian');
                    }
                    else
                    {
                        $this->data['pesan'] = 'Proses tambah data gagal';
                        $this->load->view('template', $this->data);
                    }
                }
                else
                {
                    $this->load->view('template', $this->data);
                }
            }
            else
            {
                $this->load->view('template', $this->data);
            }
        }
    }

this is cari_semua() in the model

public function cari_semua()
    {
        return $this->db->order_by('id_penguji', 'ASC')->get($this->db_tabel)->result();
    }

2 Answers2

0

you need to sterilize your code a little more try the following, this code should if nothing more tell you what going wrong, it WONT fix the issue you are having.

public function tambah()
{
    $this->data['breadcrumb']   = 'Pengujian > Tambah';
    $this->data['main_view']    = 'view_pengujian/pengujian_form';
    $this->data['form_action']  = 'pengujian/tambah';
    $penguji = $this->penguji->cari_semua();
    if($penguji)
    {
        if(is_array($penguji))
        {
        foreach($penguji as $row)
        {
            $this->data['option_pengujian'][$row->id_penguji] = $row->penguji;
        }
        }
        else
        {
        return "this aint a array";
        die;
    }
    else
    {
        $this->data['option_pengujian']['00'] = '-';
        $this->data['pesan'] = 'Data penguji tidak tersedia. Silahkan isi dahulu data penguji.';
        // if submit
        if($this->input->post('submit'))
        {
            if($this->siswa->validasi_tambah())
            {
                if($this->siswa->tambah())
                {
                    $this->session->set_flashdata('pesan', ' Proses tambah data berhasil');
                    redirect('pengujian');
                }
                else
                {
                    $this->data['pesan'] = 'Proses tambah data gagal';
                    $this->load->view('template', $this->data);
                }
            }
            else
            {
                $this->load->view('template', $this->data);
            }
        }
        else
        {
            $this->load->view('template', $this->data);
        }
    }
}
Zapps Ceo
  • 164
  • 13
0
...
foreach($penguji->row() as $row){
...

OR

...
foreach($penguji->result() as $row){
...

OR : if you want to return it ($penguji) as an array from the model, just add it (->row() or ->result()) at the end of the variable you'd to return.

If you want it easier to learn, please write the script neatly.

here's for your model

    public function cari_semua()
        {
            $this->db->order_by('id_penguji', 'ASC');
            return $this->db->get($this->db_tabel)->result(); 
// You have made the result as an array here. 
//So, you don't need to use `->result` in the controller.
        }

But, if the model function contains some errors, you will never get your result shows up, there will be error page instead of it.

Oki Erie Rinaldi
  • 1,835
  • 1
  • 22
  • 31
  • then i got this : Fatal error: Call to a member function result() on a non-object... Sorry I just start using this codeigniter in this project – Vilat Sasax Aug 18 '14 at 03:27