Reputation: 2466
This is how the $conversationArray
array look like,
array(7) {
[0]=>
array(2) {
["id"]=>
string(1) "1"
["timestamp"]=>
int(0)
}
[1]=>
array(2) {
["id"]=>
string(1) "3"
["timestamp"]=>
int(0)
}
[2]=>
array(2) {
["id"]=>
string(1) "4"
["timestamp"]=>
int(0)
}
[3]=>
array(2) {
["id"]=>
string(1) "5"
["timestamp"]=>
int(0)
}
Now I have to check against a table if any of the conversation id has timestamp more than what's given. If yes I need the affected conversation_id.
I'm not sure how to take id and timestamp from $conversationArray
array to fit into this query.
$query = '
SELECT conversation_id FROM tbl_notification
WHERE timestamp IN >implode(',', $timestamp),
AND conversation_id IN >implode(',', $id)
';
Upvotes: 0
Views: 39
Reputation: 8012
What you need to do is get the IDs
and Timestamps
in separate array and perform implode()
on each.
To get the separate array you can use array_column() which returns the values from a single column from the input array.
So to get the IDs and Timestamps in single array you would do something like this,
$ids = array_column($mainarray, 'id');
$timestamps = array_column($mainarray, 'timestamp');
Now you can perform implode() on each of them to query the database.
Consider using Prepared statements for SQL queries to avoid SQL injection attacks.
Upvotes: 1