1

i have trouble when open my web and its said Call to a member function result_array() on a non-object and i cant figure out how to solve it. i hope any of you guys can help me out.

so this is my web controller

 <?php
    defined('BASEPATH') OR exit('No direct script access allowed');

     class Web extends CI_Controller {

    public function index(){
        $data = array(
            "produk_populers" => $this->mymodel->GetProduk()->result_array()

    );

    $comp = array(
        "header" => $this->load->view("header",array(),true),
        "navbar" => $this->load->view("navbar",array(),true),
        "iklan" => $this->load->view("iklan",array(),true),
        "produk_populer" => $this->load->view("produk_populer",$data,true),
        "kategori" => $this->load->view("kategori",array(),true),
        "footer" => $this->load->view("footer",array(),true),

    );

    $this->load->view("index",$comp);

    }

    public function html_produk_populer(){
        $data = array(
            "produk_populer" => $this->mymodel->GetProduk()
    );
        return $this->load->view("produk_populer",$data,true);

    }



}

and this is my produk_populer.php

    <div class="allcontain">
    <div class="feturedsection">
    <h1 class="text-center"><span class="bdots">&bullet;</span>P R O D U K<span class="carstxt">P O P U L E R</span>&bullet;</h1>
  </div>


    <div class="feturedimage">
        <div class="row firstrow">
            <div class="col-lg-6 costumcol colborder1">
                <div class="row costumrow">

                    <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 img1colon">
                        <img src="<?php echo base_url()."assets/"; ?>images/<?php echo $produk_populer['gambar_produk']; ?>" alt="floridina">
                    </div>

                <?php foreach ($produk_populers as $produk_populer) { ?>
                    <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 txt1colon">
                        <div class="featurecontant">
                            <h1><?php echo $produk_populer['nama_produk']; ?></h1>
                            <p><?php echo $produk_populer['info_produk']; ?></p>
                            <h1><?php echo $produk_populer['harga_produk']; ?></h1>
                            <!--<<button id="btnRM" onClick="rmtxt()">READ MORE</button>
                            <div id="readmore">
                                    <h1></h1>
                                    <p><br>
                                    sed do eiusmod tempor incididunt <br>"Lorem ipsum dolor sit amet, consectetur ,<br>
                                    sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1 ,
                                    sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1
                                    sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1<br>
                                    </p>
                                    <button id="btnRL">READ LESS</button>
                            </div>-->

                        </div>

                    </div>
                        <?php } ?>
                </div>
            </div>


                <!--<div class="col-lg-6 costumcol colborder2">
                <div class="row costumrow">
                <?php //foreach ($produk_populers as $produk_populer) { ?>
                    <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 img2colon">
                        <img src="<?php //echo base_url()."assets/"; ?>images/<?php //echo $produk_populer['gambar_produk']; ?>" alt="floridina">
                    </div>


                    <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 txt1colon ">
                        <div class="featurecontant">
                            <h1><?php //echo $produk_populer['nama_produk']; ?></h1>
                            <p><?php //echo $produk_populer['info_produk']; ?></p>
                            <h1><?php //echo $produk_populer['harga_produk']; ?></h1>

                            <div id="readmore">
                                    <h1></h1>
                                    <p><br>
                                    sed do eiusmod tempor incididunt <br>"Lorem ipsum dolor sit amet, consectetur ,<br>
                                    sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1 ,
                                    sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1
                                    sed do eiusmod tempor incididunt"Lorem ipsum dolor sit amet, consectetur1<br>
                                    </p>
                                    <button id="btnRL">READ LESS</button>
                            </div>
                        </div>
                    </div>

                    <?php } ?>

                </div> -->

            </div>

        </div>
    </div>

also this is mymodel.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Mymodel extends CI_Model {
public function GetProduk($where=""){
    $data = $this->db->query('select * from produk');
    return $data -> result_array();

}



}

so that is all i need to ask, i hope theres anyone who can help me. Thanks

4
  • 1
    Show us the code for the class GetProduk() Commented Feb 16, 2017 at 11:43
  • 1
    You have not mentioned model code so mention first Commented Feb 16, 2017 at 11:45
  • this is the model code. i named it mymodel.php Commented Feb 16, 2017 at 12:01
  • Did you try var_dump $this->db? What I am questioning if you did load DB somewhere or not, Commented Feb 16, 2017 at 12:11

2 Answers 2

1

Following should work assuming you have loaded DB class.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Mymodel extends CI_Model {
public function GetProduk($where=""){
    $data = $this->db->query('select * from produk');
    return $data;

}



}
Sign up to request clarification or add additional context in comments.

Comments

0
$this->mymodel->GetProduk()->result_array();

$this->mymodel is not working. You didn't load model. You have to load mymodel before call it by using $this->load->model('mymodel'). Or also you can load it from globally by using autoload.php

5 Comments

but i already load it by using autoload.php but it still wont work. thanks for the fast answer
What is returning by your GetProduk() function? Is it an object of db? Can you give us that function or details?
$this->mymodel->GetProduk()->result_array() this will work only if $this->mymodel->GetProduk() returns object of db e.g return $this->db->get('banks');
i already edited my post and there is the model code. is there anything wrong with it?
You are already returning return $data -> result_array(); So why you again calling result_array(). $this->mymodel->GetProduk() is returning an array to you. Just use it. no need of calling this $this->mymodel->GetProduk()->result_array(); Call only $this->mymodel->GetProduk();

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.