MySQL和PHP-如何显示字段值等于x的所有行? [英] MySQL and PHP - how to display all rows where field value equals x?

查看:81
本文介绍了MySQL和PHP-如何显示字段值等于x的所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

我要显示的是Position = QB的所有行.仅某些字段会出现在 行.

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

赞:

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.

推荐答案

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

这篇关于MySQL和PHP-如何显示字段值等于x的所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆