I have a mysql database that looks like this
+----+----------+---------+----------------------------------+---------------------+
| id | field_id | user_id | value | last_updated |
+----+----------+---------+----------------------------------+---------------------+
| 1 | 1 | 1 | admin | yyyy-mm-dd hh:mm:ss |
| 3 | 5 | 1 | a:1:{i:0;s:2:"18";} | yyyy-mm-dd hh:mm:ss |
| 4 | 1 | 2 | testuser1 | yyyy-mm-dd hh:mm:ss |
| 5 | 5 | 2 | a:2:{i:0;s:2:"19";i:1;s:2:"18";} | yyyy-mm-dd hh:mm:ss |
+----+----------+---------+----------------------------------+---------------------+
I understand that a normal sql query will not be suitable so instead I need to pull all the data into php to then sort through it.
What I want is to get any user_id that has a number, lets say "19" in field_id
5. In that example, the array should read "2". Or I could search for "18" in field_id
5 and the array would return "1,2".
To get the database, I am using the following
<?php
global $wpdb;
$table_name = $wpdb->prefix . "bp_xprofile_data";
$retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name" );
$strDB = maybe_unserialize( $retrieve_data);
echo print_r($strDB, true);
?>
Which returns:
Array ( [0] => stdClass Object ( [id] => 1 [field_id] => 1 [user_id] => 1 [value] => admin [last_updated] => 2017-09-21 12:38:20 ) [1] => stdClass Object ( [id] => 3 [field_id] => 5 [user_id] => 1 [value] => a:1:{i:0;s:2:"18";} [last_updated] => 2017-09-21 12:38:20 ) [2] => stdClass Object ( [id] => 4 [field_id] => 1 [user_id] => 2 [value] => testuser1 [last_updated] => 2017-09-23 01:43:50 ) [3] => stdClass Object ( [id] => 5 [field_id] => 5 [user_id] => 2 [value] => a:2:{i:0;s:2:"19";i:1;s:2:"18";} [last_updated] => 2017-09-23 01:43:50 ) )
I can't work out how I can then sort through this data. I tried to find sections of string but this was not working.