开发者

Comparing two dynamic tables in PHP

So I have a league table being populated by a mysql database, what I am trying to do, is have an arrow next to there name stating whether or not they have moved up or down in position since the previous race, this is easy to do this with the member who is logged in, but how can I achieve this with every member in the table? I can do the query below to find out where they was in the standings from the race before, just by running the query below again but changing the case statements to Case When r.track_id = '$chosentrack'-1, and that will give me the the standings from the race before, but how can I compare that table to current standings??? and have the arrow going up or down if each member has moved up or down.

any help would be great, thanks a lot.

$result = mysql_query(" SELECT m.member_id, m.teamname, 
    Sum(Case When r.track_id = '$chosentrack' AND r.track_id >= l.start_race 
    Then total_points Else 0 End) LastRacePoints,
    Sum(Case When r.track_id <= '$chosentrack' AND r.track_id >= l.start_race
    Then total_points Else 0 End) TotalPoints 
    FROM members m
    Join members_leagues l
    On l.member_id = m.member_id  
    Join member_results r
    On r.member_id = m.member_id
    Where l.league_id = '$chosenleague'
    Group By m.member_id
    Order By TotalPoints Desc, LastRacePoints DESC, m.teamname Desc ") 
    or die ("Error - could not display league");

    $i = 0;
    $found = false;
    $team_position = 0;

  while (!$found && $row = mysql_fetch_row($result)){
    $i++;
    if ($row[0] == $session_id){
    $found = true;
    $team_position = $i;
    }
    }

    $rowsPerPage = 6;

    $pageNum = ceil($team_position/$rowsPerPage);

    if(isset($_GET['page'])){
        $chosenpage = mysql_real_escape_string($_GET['page']);
        $pageNum = $chosenpage;
    }

    $offset = ($pageNum - 1) * $rowsPerPage;
    $counter = $offset + 1;

    $result = mysql_query("SELECT m.member_id, m.teamname, 
    Sum(Case When r.track_id = '$chosentrack' AND r.track_id >= l.start_race 
    Then total_points Else 0 End) LastRacePoints,
    Sum(Case When r.track_id <= '$chosentrack' AND r.track_id >= l.start_race
    Then total_points Else 0 End) TotalPoints 
    FROM members m
    Join members_leagues l
    On l.member_id = m.member_id  
    Join member_results r
    On r.member_id = m.member_id
    Where l.league_id = '$chosenleague'
    Group By m.member_id
    Order By TotalPoints Desc, LastRacePoints DESC, m.teamname Desc " . "
    LIMIT $offset, $rowsPerPage") 
    or die ("Error - could not display league");

        echo "<table id=\"subleaguetable\" cellpadding=\"0\" cellspacing=\"0\">";
        echo "<tr><th width=\"30px\" style=\"text-align: center;\">Pos</th>";
        echo "<th width=\"200px\" style=\"background-color: #f13740;\">Team</th>";
        echo "<th width=\"200px\" style=\"text-align: center; background-color: #f13740;\">Points/Overall</th>";
        echo "<th width=\"100px\" style=\"text-align: center; background-color: #f13740;\">Points/Last Race</th>";
        echo "&开发者_运维知识库lt;/tr>";

    while($row = mysql_fetch_assoc($result)){

    echo "<tr><td style=\"text-align:center;\">";
    echo $counter;
    echo "</td>";
    if($row['member_id'] == $session_id){
    echo "<td style=\"background-color:#e4212a; color:#FF9912;\">";
    echo $row['teamname'];
    echo "</td>";
    }else{
    echo "<td style=\"background-color:#e4212a;\">";
    echo $row['teamname'];
    echo "</td>";
    }
    echo"<td style=\" background-color:#e4212a; text-align:center;\">";
    echo $row['TotalPoints'];
    echo "</td><td style=\" background-color:#e4212a; border-bottom:solid 1px #ca0811;  text-align:center;\">";
    echo $row['LastRacePoints'];
    echo "</td></tr>";
    }
    $counter++;
    }
    echo "</table>";


Have you tried INTERSECT in your query?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜