PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE Users ( id int, field_id int, User_id int, Value varchar(255) ); INSERT INTO Users VALUES (234, 52, 123, 'a:4:{i:0;s:3:"615";i:1;s:3:"619";i:2;s:3:"918";i:3;s:3:"570";}'), (874, 52, 173, 'a:3:{i:0;s:2:"23";i:1;s:3:"619";i:2;s:3:"918";}'), (42, 52, 143, 'a:2:{i:0;s:4:"2372";i:1;s:3:"615";}');
Copy Clear
Copy Format Clear
<?php $stmt = $pdo->query("SELECT * FROM Users WHERE field_id= 52") or die; $users = $stmt->fetchAll(PDO::FETCH_ASSOC); //Unserialize and join user arrays $count_users = array_reduce( $users, function($res, $u) { return array_merge($res, unserialize($u['Value'])); }, [] ); //Print count values $sort = array_count_values($count_users); arsort($sort, SORT_NUMERIC); foreach ($sort as $key => $row) { echo $key . '.' . $row . "\r\n"; }
Show:  
Copy Clear