获取MySQL或PHP的信息

时间:2014-02-16 15:48:28

标签: php mysql

我无法正确显示联赛积分榜。 我有一个CSV文件,所有团队除以部门和会议 (基本上试图像NHL排名那样展示我的排名)

显示每个部门的前3个团队 然后会显示会议中排名前3位的前2名队伍。

这是我现在的代码

//Query Central //
$QueryCentral="SELECT * FROM QNHLProTeamV2 WHERE Division='$CentralDivision' ORDER by Points DESC, GP ASC, W DESC, GoalDiff DESC LIMIT 3";
$ResultCentral=mysql_query($QueryCentral);
$NumCentral=mysql_num_rows($ResultCentral);

//Query Pacific //
$QueryPacific="SELECT * FROM QNHLProTeamV2 WHERE Division='$PacificDivision' ORDER by Points DESC, GP ASC, W DESC, GoalDiff DESC LIMIT 3";
$ResultPacific=mysql_query($QueryPacific);
$NumPacific=mysql_num_rows($ResultPacific);

//Query West Wild Card //
$QueryWestWildCard="SELECT * FROM QNHLProTeamV2 WHERE Conference='$WesternConference' ORDER by Points DESC, GP ASC, W DESC, GoalDiff DESC LIMIT 6,20";
$ResultWestWildCard=mysql_query($QueryWestWildCard);
$NumWestWildCard=mysql_num_rows($ResultWestWildCard);

前2个查询有效,我确实得到了每个部门的前3个 但对于Wild Card,我只能弄清楚如何在没有的情况下让所有球队顺利进入 前6名。 如何显示不属于前三名的团队?

1 个答案:

答案 0 :(得分:0)

以下是一些可以解决问题的代码。但是,您需要使用实际列的名称更新$ row [“TeamName”]。

//Query Central //
$QueryCentral="SELECT * FROM QNHLProTeamV2 WHERE Division='$CentralDivision' ORDER by Points DESC, GP ASC, W DESC, GoalDiff DESC LIMIT 3";
$ResultCentral=mysql_query($QueryCentral);
$NumCentral=mysql_num_rows($ResultCentral);
$i=0;
while($row = mysqli_fetch_array($ResultCentral);
{
    $top[$i]="\"".$row["TeamName"]."\"";
    $i++;
}

//Query Pacific //
$QueryPacific="SELECT * FROM QNHLProTeamV2 WHERE Division='$PacificDivision' ORDER by Points DESC, GP ASC, W DESC, GoalDiff DESC LIMIT 3";
$ResultPacific=mysql_query($QueryPacific);
$NumPacific=mysql_num_rows($ResultPacific);
while($row = mysqli_fetch_array($ResultPacific);
{
    $top[$i]="\"".$row["TeamName"]."\"";
    $i++;
}

//Generate list - delimited by comma
$toplist = implode(",", $top);

//Query West Wild Card //
$QueryWestWildCard="SELECT * FROM QNHLProTeamV2 WHERE Conference='$WesternConference' and NOT IN ($toplist) ORDER by Points DESC, GP ASC, W DESC, GoalDiff DESC LIMIT 3";
$ResultWestWildCard=mysql_query($QueryWestWildCard);
$NumWestWildCard=mysql_num_rows($ResultWestWildCard);

或者,您可以将此查询用于通配符(看起来更混乱):

$QueryWestWildCard="SELECT * FROM QNHLProTeamV2 
WHERE Conference='$WesternConference' 
and NOT IN (SELECT TeamName FROM QNHLProTeamV2 WHERE Division='$CentralDivision' ORDER by Points DESC, GP ASC, W DESC, GoalDiff DESC LIMIT 3) 
AND NOT IN (SELECT TeamName FROM QNHLProTeamV2 WHERE Division='$PacificDivision' ORDER by Points DESC, GP ASC, W DESC, GoalDiff DESC LIMIT 3) 
ORDER by Points DESC, GP ASC, W DESC, GoalDiff DESC LIMIT 3";