Location: PHPKode > projects > Gatito Prediction League > gatito_pred_league/admin/total.php
<?
include "../templates/connect_db.php";
//check and set current week
$query=mysql_query("SELECT * FROM users WHERE username ='admin'");
while ($row =@ mysql_fetch_array($query)) {@$week=$row[week];
$new_week=$week+1;}; 

//get result from check table
$query=mysql_query("SELECT * FROM checker WHERE week ='$week'");
while ($row =@ mysql_fetch_array($query)) { 
	@$game=$row[game]; @$h_score=$row[h_score];@$h_team=$row[home_team];@$a_team=$row[away_team]; @$a_score=$row[a_score];@$result=$row[result];

echo "<br><B>game $game: $h_team $h_score v $a_score $a_team</B><br>";
//check results aginst user predictions and assign points
$uquery=mysql_query("SELECT * FROM results WHERE week ='$week' and game = '$game' order by username");
while ($urow =@ mysql_fetch_array($uquery)) {

@$uh_score=$urow[h_score]; 
@$ua_score=$urow[a_score];
@$uresult=$urow[result]; 
@$user=$urow[username];
if ($user != "admin8") {
	
	$pts=0;
	$sco=0;
	$res=0;
	if ($uresult == $result) {$res=1;}
if ($h_score == $uh_score AND $a_score == $ua_score) {$sco=2;};
$pts=$res+$sco;
echo "$user: prediction $uh_score v $ua_score -----points $pts<br>";
// add points to results table
	mysql_query("UPDATE results SET pts = '$pts' WHERE username = '$user' AND week = '$week' AND game='$game'")or die (mysql_error()); 
	};

};
};
//total up points for week
$tquery=mysql_query("SELECT * FROM users");
while ($trow =@ mysql_fetch_array($tquery)) {@$user=$trow[username];
$pts=0;
$query=mysql_query("SELECT pts FROM results WHERE username='$user'");
while ($row =@ mysql_fetch_array($query)) {@$tot=$tot+$pts;
echo $pts;};
echo "$user: $pts points <br>";
$tquery=mysql_query("SELECT * FROM users");
while ($trow =@ mysql_fetch_array($tquery)) {@$user=$trow[username];
$pts=0;
$tot=0;
$query=mysql_query("SELECT pts FROM results WHERE username='$user'");
while ($row =@ mysql_fetch_array($query)) {
@$pts=$row[pts];
	@$tot=$tot+$pts;
};


//insert points to users and advance to next week 
echo "<br> $user: $tot points <br>";
mysql_query("UPDATE users SET score = '$tot' WHERE username='$user'");
mysql_query("UPDATE users SET week = '$new_week' WHERE username='$user'");
};
};
// insert week totals
echo "week totals for $week";
include "connect_db.php";
$query=mysql_query("SELECT * FROM users");
while (
$row =@ mysql_fetch_array($query)) {$user=$row['username'];$team=$row[team]; $tot="0";
$squery=mysql_query("SELECT * FROM results WHERE username = '$user' AND week ='$week'");
while ($srow =@ mysql_fetch_array($squery))
{$tot=$tot + $srow['pts'];
$weekending= $srow['close_date'];}

if ($tot > 0) {
	echo "week:$week $user : $tot <br/>";
mysql_query ("INSERT INTO week_totals  Values ('','$user','$team','$tot','$week','$weekending')") or die (mysql_error());
};
};
include "teamscores.php";
	?>
Return current item: Gatito Prediction League