1

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

In my model:

public 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:

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

    print_r($recipients);
}

What does row_array() return in CodeIgniter?

2
  • check the doc codeigniter.com/userguide3/database/results.html Commented Mar 2, 2019 at 7:24
  • row_array() returns a flat array representing the first qualifying row of the query. If there were no qualifying rows, then null is returned. For this reason, it is unstable to try to access the email element of a potentially null value. You will need to null coalesce. Commented Mar 5 at 22:40

1 Answer 1

1

The row_array() and row() will return only one row. Use result_array() or result() if you want to fetch multiple rows. See result_array()

Change $row = $query->row_array(); to $row = $query->result_array();

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.