I have this Function:
function getLow()
{global $db_prefix, $min;
//get latest week with all entered scores
$lastCompletedWeek = getLastCompletedWeek(); $sql = "select u.userID, u.teamName "; $sql .= "from " . $db_prefix . "users u "; $query = mysql_query($sql); while ($result = mysql_fetch_array($query)) { for($i = 1; $i <= $lastCompletedWeek; $i++) { $userScore = getLowScore($i, $result['userID']); $win[][week] = $i; $win[][user] = $result['userID']; $win[][teamName] = $result['teamName']; $win[][score] = $userScore; } $count = count($win); $lowest = 0; $min[score] = PHP_INT_MAX; $min[user] = $result['userID']; $min[teamName] = $result['teamName']; for($i = 0; $i < $count; $i++) { if($win[$i + 1]['user'] == $result['userID']) { if($win[$i + 3]['score'] < $min[score]) { $min[score] = $win[$i + 3]['score']; $lowest = $i; } } } unset($win[$lowest]); unset($win[$lowest + 1]); unset($win[$lowest + 2]); unset($win[$lowest + 3]); $win = array_values($win); //print_r ($min); //echo $min[teamName] . ' ' . $min[score] . ' '; }}
when I call it from another .php file like this:
getLow($min);
I only get the last record....why?
Here is the getLowScores functio as well.
function getLowScore($week, $userID) { global $db_prefix, $user; $score = 0; //get array of games $games = array(); $sql = "select from " . $db_prefix . "schedule where weekNum = " . $week . " order by gameTimeEastern, gameID"; $query = mysql_query($sql); while ($result = mysql_fetch_array($query)) { $games[$result['gameID']]['gameID'] = $result['gameID']; $games[$result['gameID']]['homeID'] = $result['homeID']; $games[$result['gameID']]['visitorID'] = $result['visitorID']; $games[$result['gameID']]['tie'] = 1; if (($result['homeScore'] + (($result['visitorSpread'] -1))) > ($result['visitorScore'] + (($result['homeSpread'] -1)))) { $games[$result['gameID']]['winnerID'] = $result['homeID']; } if (($result['visitorScore'] + (($result['homeSpread'] -1))) > ($result['homeScore'] + (($result['visitorSpread'] -1)))) { $games[$result['gameID']]['winnerID'] = $result['visitorID']; } if (($result['visitorScore'] + ($result['homeSpread'] -1)) == ($result['homeScore'] + ($result['visitorSpread'] * -1))) { $games[$result['gameID']]['winnerID'] = $result['tie']; } } //loop through player picks & calculate score $sql = "select p.userID, p.gameID, p.pickID, p.points, u.paid "; $sql .= "from " . $db_prefix . "picks p "; $sql .= "inner join " . $db_prefix . "users u on p.userID = u.userID "; $sql .= "inner join " . $db_prefix . "schedule s on p.gameID = s.gameID "; $sql .= "where s.weekNum = " . $week . " and u.userID = " . $userID . " "; $sql .= "order by u.lastname, u.firstname, s.gameTimeEastern"; $query = mysql_query($sql); while ($result = mysql_fetch_array($query)) { if (!empty($games[$result['gameID']]['winnerID']) && $result['pickID'] == $games[$result['gameID']]['winnerID']) { //player has picked the winning team $score++; } if ($result['tie'] == $games[$result['gameID']]['winnerID']) { //player has picked the winning team $score++; } } return $score;}
Thanks in advance for helping!! This is driving me crazy?