DonX
DonX

Reputation: 45

CodeIgniter, query only shows 1 record in view

I'm new with PHP and using MVC. My script seems to be only showing a single record instead of multiple records even in a foreach loop.

Here's my code:

Model

public function rp_reach_rate_stmt()
{
    $stmt = $this->db->select(array('user_id','user','full_name'))->get('vicidial_users',10);
    //  $stmt = $this->db->get('vicidial_users',10);
    return $stmt->row();
}

Controller

public function rp_reach_rate()
{

    $this->load->model('db_model');
    $data['sqlstmt'] = $this->rp_reach_rate_get_data();
    $this->load->view('RP_ReachRate',$data);
}

private function rp_reach_rate_get_data()
{
    $this->load->model('db_model');
    $result = $this->db_model->rp_reach_rate_stmt();
    return $result;
} 

View

<?php 
    var_dump($sqlstmt);echo '<br />';
    foreach($sqlstmt as $row)
    {
        echo  $row." ";

    }
?>

RESULT

object(stdClass)#19 (3) { ["user_id"]=> string(1) "1" ["user"]=> string(4) "6666" ["full_name"]=> string(5) "Admin" }

1 6666 Admin

I might have missed something.

Upvotes: 0

Views: 1721

Answers (1)

Rejoanul Alam
Rejoanul Alam

Reputation: 5398

public function rp_reach_rate_stmt()
    {
        $stmt = $this->db->select(array('user_id','user','full_name'))->get('vicidial_users',10);
    //  $stmt = $this->db->get('vicidial_users',10);
        return $stmt->result_array();
    }

change $stmt->row() to $stmt->result_array() as above and test. It will return result with all rows & as array. If you need access as object then use result() instead of result_array()

Upvotes: 1

Related Questions