简体   繁体   English

通过MySQL或PHP获取信息

[英]getting info with MySQL or PHP

I'm having trouble displaying my league standings correctly. 我无法正确显示我的联赛排名。 I have a CSV file with all teams divided by Divisions and Conferences (basically trying to display my standings like the NHL standings) 我有一个CSV文件,其中所有团队均按部门和会议划分(基本上是尝试显示我的排名,例如NHL排名)

The top 3 teams of each division are displayed then the top 2 teams in the conference that are not in the top 3 of divisions are displayed. 将显示每个部门的前3个团队,然后显示会议中不在部门的前3个团队中的前2个团队。

Here is the code I have now 这是我现在的代码

//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);

The first 2 queries work and I do get the top 3 of each division but for the Wild Card I could only figure out how to get all the teams in order without top 6. How can I display the teams that are NOT in top 3 of divisions? 前2个查询有效,但我确实获得了每个分区的前3名,但是对于Wild Card,我只能弄清楚如何使所有团队排在第6位而没有前6名。如何显示不在前3名中的团队师?

Here is some code that should do the trick You will need to update the $row["TeamName"] with the actual column's name, however. 这是一些应该起作用的代码,但是,您将需要使用实际列的名称更新$ 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);

Or, you could use this query for the wild card (looks messier): 或者,您可以对通配符使用以下查询(看起来比较混乱):

$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";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM