I'm trying to get all the values for all sessions under the "session_value" column in the "wp_woocommerce_sessions" DB table.
The following code does the job but for some reason is duplicating the result 6 times, giving me 6 arrays with the exact same content.
global $wpdb;
$wooSessions = $wpdb->get_col( "SELECT session_value FROM {$wpdb->prefix}woocommerce_sessions" );
$wooCookies = implode(" ", $wooSessions);
I'm reading about OBJECT_K in the documentation which in theory discards duplicated keys but I don't know how to apply it. If I add OBJECT_K inside the get_col parenthesis the code stops working.
This is the output var_dump ($wooSessions); is giving me:
array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}
array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}
array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}
array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}
array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}
array(1) { [0]=> string(4366) "a:12:{s:4:"cart";s:2084:"a:2:{s:32:"1b4cfd194c804d1ad422a350aa2a0145…"}
Here's another example using session_id and session_key:
global $wpdb;
$wooSessions = $wpdb->get_results( "SELECT DISTINCT session_id, session_key FROM {$wpdb->prefix}woocommerce_sessions GROUP BY session_key" );
Which returns the following:
Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 [session_key] => 76f0552cff4af84e1963815c1fc4a14d ) )
Here's another example selecting session_id and group by session_id:
global $wpdb;
$wooSessions = $wpdb->get_results( "SELECT session_id FROM {$wpdb->prefix}woocommerce_sessions GROUP BY session_id" );
This is the result:
Array ( [0] => stdClass Object ( [session_id] => 2149 ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 ) )
Array ( [0] => stdClass Object ( [session_id] => 2149 ) )
Any ideas that can point me in the right direction? Thanks in advance.