View file tennis/tennis/tour.php

File size: 2.45Kb
<?php
/** Author: ArseN
/*	icq: 799956
/*	email: [email protected]
/*	site: http://softmob.ru
*/
header("Content-type: text/html; charset=UTF-8");
include "config.php";

$points_array = array();

// выбираем последне созданный турнир он же текущий
$result = mysql_query("SELECT `id_tour` FROM `tournament` WHERE 1 ORDER BY `id_tour` DESC;");
$row = mysql_fetch_array($result);
if(empty($row))
{
	echo "Нет турниров!";
	exit;
}
$id_tour = $row['id_tour'];

$result_user = mysql_query("SELECT `id_user` FROM `users` WHERE 1;");
$count_user = mysql_num_rows($result_user);

for ($j=0; $j<$count_user; $j++)
{
	$row = mysql_fetch_array($result_user);
	$id_user = (int) $row['id_user'];
	
	//проверка команды наход в турнире
	$result = mysql_query("SELECT * FROM `team_in_tour` WHERE `id_user`='$id_user' AND `id_tour`=$id_tour LIMIT 1;");
	$row = mysql_fetch_array($result);
	
	if(!empty($row))
	{
		$id_team = $row['id_team'];
		$date_in_tour = $row['date'];
		$points = 0;
					
		$result = mysql_query("SELECT * FROM `users_team` WHERE `id_team`='$id_team' LIMIT 1;");
		$row = mysql_fetch_array($result);
		$id_clubs = explode(';', $row['id_club']);
		foreach ($id_clubs as $id_club)
		{
			// данные по клубам
			$result_club = mysql_query("SELECT * FROM `clubs` WHERE `id_club`=$id_club;");
			$club_data = mysql_fetch_array($result_club);
			// данные по играм
			$result_game = mysql_query("SELECT * FROM `results_game` WHERE `id_tour`=$id_tour AND `id_club`='$id_club' AND `date`>='$date_in_tour';");
			$game_num_data = mysql_num_rows($result_game);
			$text_points = " Игры:";
			for ($i = 0; $i < $game_num_data; $i++)
			{
				$game_data = mysql_fetch_array($result_game);
				$text_points .= " ".$game_data['points'];
				$points += $game_data['points'];
			}
			$points += (int)$club_data['club_points'];
			//echo $club_data['club_name']." очков:".$club_data['club_points'].$text_points;
			//echo "<br/> \n";
			
		}
		//echo "Всего набранно очков: $points <br/><hr/> \n";
		$points_array[$id_user] = $points;
	}
}
arsort($points_array);

foreach ($points_array as $id_user => $points)
{
	$result_user = mysql_query("SELECT * FROM `users` WHERE `id_user`=$id_user;");
	$user_data = mysql_fetch_array($result_user);
	
	echo $user_data['name']." очков: ".$points;
	echo " <hr/> \n";
}
?>