MySQL 和 PHP - 如何显示字段值等于 x 的所有行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10646921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:42:26  来源:igfitidea点击:

MySQL and PHP - how to display all rows where field value equals x?

phpmysqlselect

提问by Cynthia

I have a database table (ff_projections) that contains the following fields:

我有一个包含以下字段的数据库表 (ff_projections):

ID  Player  Position    Team    Pass_Yds    Pass_TDs    Int_Thrown  Rush_Yds    Rush_TDs    Rec_Yds Rec_TDs Receptions  Fumbles Extra_Pts   FG  Sacks   Int_Caught  Def_TD  ST_TD   Shutouts    Overall_Pts Total_Fantasy_Pts

What I want is to display all rows where Position = QB. Only certain fields would appear in the rows though.

我想要的是显示位置 = QB 的所有行。虽然只有某些字段会出现在行中。

Like this:

像这样:

SELECT Player, Team, Pass_Yds, Pass_TDs, Int_Thrown, Rush_Yds, Rush_TDs, Overall_Pts, Total_Fantasy_Pts  FROM ff_projections WHERE Position = 'QB';

and then display the results in a table on the web page.

然后在网页上的表格中显示结果。

回答by Ahatius

<?php
$con = mysql_connect("localhost","user","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database", $con);

$result = mysql_query("SELECT Player, Team, Pass_Yds, Pass_TDs, Int_Thrown, Rush_Yds, Rush_TDs, Overall_Pts, Total_Fantasy_Pts FROM ff_projections WHERE Position = 'QB' ORDER BY Pass_Yds DESC;");

while($row = mysql_fetch_array($result))
  {
  echo $row['Player'];
  echo $row['Team'];
  ....
  }

mysql_close($con);
?>