通过MySQL或PHP获取信息

通过MySQL或PHP获取信息

我无法正确显示我的联赛排名。
我有一个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名
如何显示不在前3名中的球队?

最佳答案

这是一些可以解决问题的代码,但是,您将需要使用实际列的名称来更新$ 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";

关于php - 通过MySQL或PHP获取信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21813458/

10-11 07:44