--------------------------------------------------------------------------------
Hello All,
I am hoping that someone can tell me where I am going wrong. I am pulling out my hair trying to figure this out. Here is what I am trying accomplish:
Survivor Football Pool -
1.) Before game starts, a "?" is in place of the team that the person selected.
2.) After game starts, the team that player choose becomes visible
3.) If win, cell is green, if lost, cell is red
Right now 1 and 3 are working fine
2 is a little shakey. I can't get the team to be visible once game starts, but it will show if I enter the score which signifies the game is over.
Here is the code:
Code: Select all
Here is the code:
PHP Code:
<?php
$datenow=time() + 7200;
$sql="select min(gametime) as t FROM ((select gametime from phpfb_schedule WHERE week=$week) as x)"; // When does the first game of the week start?
$tresult = mysql_query($sql);
$tres = mysql_fetch_object($tresult);
$mintime = $tres->t;
//echo "$mintime $datenow<br>";
$alllocked = ($mintime < $datenow);
//echo "$week $alllocked<br>";
$base = "SELECT Max(Week) as x, user FROM ((SELECT DISTINCT survivorpool.* from survivorpool, phpfb_schedule WHERE ((pick=hid AND hscore>vscore) OR (pick=vid AND hscore<vscore) AND Pick<>'OUT' AND Pick<>'BAD' AND Pick<>'XXX' OR survivorpool.week=1)) as y) GROUP BY User ORDER BY x DESC";
//$base = "select user, count(*) as x FROM survivorpool WHERE Pick<>'OUT' AND Pick<>'BAD' AND Pick<>'XXX' GROUP BY User ORDER BY x DESC";
$resultOrig = mysql_query($base);
$currentnum = 0;
$numrows = mysql_num_rows($resultOrig);
while ($all[$currentnum++] = mysql_fetch_object($resultOrig)){}
mysql_free_result($resultOrig);
for ($x = 0; $x < $numrows; $x++){
$next = $all[$x];
$p++;
//while ($next = mysql_fetch_object($resultOrig)){
$current=$next->user;
$user=$current;
//$sql = "select user, Week, Pick FROM survivorpool WHERE user='$current' AND Week<$week";
$sql = "select user, Week, Pick FROM survivorpool WHERE user='$current' AND Week<=$week ORDER BY Week ASC";
//echo "$sql<br>";
$lastweek=0;
$done=false;
$resultA = mysql_query($sql) or die(mysql_error());
//echo mysql_errno() . " code<br>";
//echo mysql_num_rows($resultA) . " rows, " . mysql_num_fields($resultA) . " fields<br>";
//$row = mysql_fetch_object($resultA);
//echo $row->user . " " . $row->Week . " " . $row->Pick . " END<br>";
//echo "$week<br>";
while(($result=mysql_fetch_object($resultA))){
$done=false;
while (!$done){
// echo $lastweek . " " . ($result->Week-1) . "<br>";
// var_dump($row);
// echo $result->user . " " . $result->Week . " " . $result->Pick . "<br>";
if ($lastweek == ($result->Week - 1)){
// echo "OK on $lastweek<br>";
$lastweek++;
$sql2="SELECT * FROM phpfb_schedule WHERE (hid='" . $result->Pick . "' OR vid='" . $result->Pick . "') AND week=" . $result->Week;
// echo "$sql2<br>";
$resultB = mysql_query($sql2);
// echo mysql_num_rows($resultB) . "<br>";
if ($result2=mysql_fetch_object($resultB)){
if ((($result->Pick == $result2->hid && $result2->hscore <= $result2->vscore) || ($result->Pick == $result2->vid && $result2->hscore >= $result2->vscore)) && !($result2->hscore == 0 && $result2->vscore == 0)){ // Wrong pick
// echo "$user made wrong pick at $lastweek<br>";
$done=true;
$picks[$user][$lastweek][0] = $result->Pick;
$picks[$user][$lastweek][1] = 1;
}
else{ // Correct pick or in progress
if ($result2->vscore == 0 && $result2->hscore == 0){ // Game in progress
$picks[$user][$lastweek][1] = 2;
$done=true;
if (!($lastweek == $week && !$alllocked)){
$picks[$user][$lastweek][0] = $result->Pick;
}
else{
$picks[$user][$lastweek][0] = "?";
}
}
else{
// echo "$user made good pick at $lastweek<br>";
$picks[$user][$lastweek][0] = $result->Pick;
$picks[$user][$lastweek][1] = 0;
}
$done=true;
}
}
else{ // Invalid pick
$picks[$user][$lastweek][0] = "BAD";
$picks[$user][$lastweek][1] = 1;
$done=true;
}
}
else{ //Missed week
$lastweek++;
// echo "$user misssed $lastweek<br>";
if (!($lastweek == $week && !$alllocked)){
$picks[$user][$lastweek][0] = "MISSED";
}
else{
$picks[$user][$lastweek][0] = "?";
}
$picks[$user][$lastweek][1] = 1;
}
}
}
//echo "$user $lastweek $week<br>";
if ($lastweek<$week){ //Missed week
$lastweek++;
// echo "$user missed $lastweek<br>";
if ($alllocked){
// echo "$user MISSED<br>";
$picks[$user][$lastweek][0] = "MISSED";
$picks[$user][$lastweek][1] = 1;
}
else{
// echo "$user?<br>";
$picks[$user][$lastweek][0] = "?";
$picks[$user][$lastweek][1] = 2;
}
$done=true;
}
//echo $next->User . " " . $next->x . "<BR>";
$done = false;
echo "<tr><td>$p</td><td>" . $next->user . "</td>";
for ($count = 1; $count<=$week && !$done; $count++)
{
if ($picks[$user][$count][1] == 1){ // Wrong pick
$done=true;
echo "<td bgcolor=\"red\"><img src=\"/images/" . $picks[$user][$count][0] . "l.gif\"></td>";
}
else if ($picks[$user][$count][1] == 2){ // Game in progress
$done = true;
if (match_done($picks[$user][$count][0], $count)) {
echo "<td bgcolor=\"white\">?</td>";
} else {
if ($picks[$user][$count][0] != "?") echo "<td bgcolor=\"white\"><img src=\"/images/" . $picks[$user][$count][0] . "l.gif\"></td>";
else echo "<td bgcolor=\"white\">?</td>";
}}
else{ // correct pick
echo "<td bgcolor=\"green\"><img src=\"/images/" . $picks[$user][$count][0] . "l.gif\"></td>";
}
}
if (mysql_num_rows($resultA) < $week-1) echo "<td bgcolor=\"black\"><font color=\"white\">OUT</font></td>";
echo "</tr>\n";
}
?>
</table>
Thanks,
Patsman77