Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 475
user123 Avatar asked Dec 11 '22 04:12

user123


2 Answers

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;
like image 197
Basit Avatar answered Dec 23 '22 22:12

Basit


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

use result_array()

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

like image 44
Mad Angle Avatar answered Dec 23 '22 23:12

Mad Angle