1

Here Is MY Output OF problem i want to get all reciver_id indexes from this array and after getting all indexes i want to get the result from another table users against these id's

$data['cat_row']        =       $this->messages_model->get_sentnotify($user_id);
        foreach($data['cat_row'] as $key){
            $profile    =   $key['reciver_id'];
        }
 $data['profile']        =       $this->messages_model->Sender_profile($profile);

through this code i get only 1 value of first index how to get all... getting all i want to get users from other table against each id

function Sender_profile($profile)
    {
        $this->db->where('id', $profile);
        $query = $this->db->get($this->db_table2);
        return $query->result_array();
    }

kindly help me about sql also how i get all values from database in one iteration enter image description here

2
  • You mean that you need to access each index inside of the result array, right? Commented Jan 9, 2016 at 4:49
  • i want to show name against each reciever id at one page Commented Jan 9, 2016 at 4:52

2 Answers 2

3

Code Part 1

Get all reciver_id in an array like follows:

$data['cat_row'] = $this->messages_model->get_sentnotify($user_id);

$profile = [];

foreach($data['cat_row'] as $key){

  array_push($profile, $key['reciver_id']);

}

$data['profile'] = $this->messages_model->Sender_profile($profile);

Code Part 2

Use Codeigniter's where_in() function.

function Sender_profile($profile) {

  $this->db->where_in('id', $profile);

  $query = $this->db->get($this->db_table2);

  return $query->result_array();

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

Comments

0

In your controller , you need to access all your receiver_id then modify your foreach loop:

$i=0;
foreach($data['cat_row'] as $key){
        $profile[$i]    =   $key['reciver_id'];
        $i++;
    }

Now you have all your receiver_id in $profile array. and pass this array in controller function and should query like this:

SELECT * FROM table WHERE id IN (5,4,3,1,6);// Just for example you need to modify your query according to your need.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.