简体   繁体   中英

Codeigniter can't fetch all data from database table

I am fetching data from mysql database table in codeigniter using following code

 $result = $this->db->get("shipping");
 $data =  $result->result_array();

But returns no data.

When I apply the limit as

$this->db->get("shipping",1,30)

The code works.

But I want to fetch all result and not by limiting it. Could anyone please let me know how do I resolve this issue. Thanks in advance.

have you tried using query rather than get?

     $sql = "
        SELECT
            *
        FROM
            shipping
    ";

    $query = $this->db->query($sql);
    $data = $query->result();

You have not put a return

https://www.codeigniter.com/user_guide/database/results.html

// This will get every result from shipping
public function somefunction() {
  $result = $this->db->get("shipping");
  return $result->result_array();
}

Controller function

public function somecontrollerfunction() {

    $this->load->model('some_model');

    $data['shipping'] = array();

    $data['shipping'] = $this->some_model->somefunction();

    // var_dump($data['shipping']);

    $this->load->view('your_view', $data);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM