<?php
require_once('../wp-load.php' );
global $wpdb;
$pl = array();
$tm = array();
$play = array();
$sql = " select game as g,(select player_id from wp_plugin_votazioni where vote != 's.v.' and vote != '' and game = g and player_id in (select distinct(id) from wp_plugin_atalantini_player where ruolo != 'ALLENATORE') group by player_id order by avg(vote) desc limit 1) as player_id, max(vote) from wp_plugin_votazioni where vote != 's.v.' and vote != '' and player_id in (select id from wp_plugin_atalantini_player) group by game order by count((vote));";
$teams = $wpdb->get_results($sql);
foreach ( $teams as $player ) {
if (!in_array($player->player_id, $pl)) {
$pl[] = $player->player_id;
}
$tm[] = $player->player_id;
}
for ($x = 0; $x < count($pl); $x++) {
$totale = 0;
for ($i = 0; $i < count($tm); $i++) {
if ($tm[$i] == $pl[$x]) {
$totale++;
}
}
$playername = "";
$playerfoto = "";
$teams = $wpdb->get_results("select nominativo, file_player from wp_plugin_atalantini_player where id = " . $pl[$x] . ";");
foreach ( $teams as $player ) {
$player->totale = $totale;
$play[] = $player;
}
}
echo json_encode($play);
?>