0

I want to take the conversation_id values from the following arrays and store them into another array so I can use it in a WHERE clause. Is that possible?

`Array ( [conversation] => Array ( 
[0] => Array ( 
[conversation_id] => 4
[conversation_subject] => This is just a test 
[conversation_last_reply] => 2016-01-03 20:12:14 
[conversation_unread] => 1 ) 
[1] => Array (
[conversation_id] => 3 
[conversation_subject] => Interview scheduled for monday [conversation_last_reply] => 2016-01-03 18:51:33 
[conversation_unread] => 1 ) 
[2] => Array ( 
[conversation_id] => 2 
[conversation_subject] => Google hangout
[conversation_last_reply] => 2016 [conversation_unread] => 1 )
[3] => Array ( 
[conversation_id] => 1 
[conversation_subject] => testing 
[conversation_last_reply] => 2016
[conversation_unread] => 1 ) ) )`

My frame work is codeignitor

2 Answers 2

1

You can defined a new array and populate that with the conversation_id and you will be using $this->db->where_in() to get the result.

$where = [];
foreach($array['conversation'] as $row){
   $where[] = $row['conversation_id'];
}

// Model code

$this->db->where_in('conversation_id', $where);

Hope that helps.

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

Comments

1

I'd suggest you familiarize yourself with PHP's built-in foreach() function.

5 Comments

i know how to do a for each loop. but how do i do the where clause please? am i going to implode it? i tried . never worked
Are you using the SELECT * in your query?
no sir. i am selecting fields in about 3 tables i have joined so . and i want the where clause to run for each of the conversation id value.
Either way, you're going to need to loop through the array and gather all the conversation_id's from that array and then use them accordingly.
if php is your passion, then come on give me an example pleaseeeee

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.