user123
user123

Reputation: 55

row_array() codeigniter return the first row only

I want to get list of email addresses from the database, what I have tried are here:

In my model:

function get_email_address_by_sector($search_by, $search_field) {
        $this->db->select('*');
        $this->db->like($search_by, $search_field);
        $query = $this->db->get('tb_company');

        $row = $query->row_array();
        return $row['email'];
    }

I want to see the data in the array with this controller:

function get_email_address($search_by, $search_field) {
        $recipients = $this->company_model->get_email_address_by_sector($search_by, $search_field);

        print_r($recipients);
    }

There are 2 records, and must be show both of them. But it shows the first record only. Is there any wrong in my code? Thank you.

Upvotes: 4

Views: 22638

Answers (3)

$result = $query->first_row('array');
return $result;

Upvotes: -1

Mad Angle
Mad Angle

Reputation: 2330

$row = $query->row_array(); // it will only one row.

use result_array()

$row = $query->result_array();// it will return all rows.

Upvotes: 3

Basit
Basit

Reputation: 1840

row_array() returns the first row only. If you want all the records to be returned, use result_array() instead

$result = $query->result_array();
return $result;

Upvotes: 12

Related Questions