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";}'), (45, 22, 12, 'a:3:{i:0;s:2:"23";i:1;s:3:"615";i:2;s:3:"918";}'), (42, 52, 143, 'a:2:{i:0;s:3:"918";i:1;s:3:"125";}');
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) { if(is_array($res)){ return array_merge($res, unserialize($u['Value']));} }, [] ); //Print count values $array=array_count_values($count_users); foreach ($array as $row) { echo "".$row.""; }
Show:  
Copy Clear