0
我需要从mysql数据库中获取查询的结果。我已经四处搜寻,我认为我应该工作,但事实并非如此。我在正确的文件夹中运行它。如果有什么人可以告诉我,这将不胜感激。我需要在HTML中显示一个MYSQL查询COUNT(*)
谢谢!
这是我的代码。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<?php
// define DB connection variables
$host = "localhost";
$user = "root";
$password = "";
// connect to the MySQL server
$db_connection = mysql_connect($host,$user,$password);
// If the connection failed:
if(!$db_connection){
echo "Error connecting to the MySQL server: " . mysql_error();
exit;
}
mysql_select_db("hockey");
// Execute an SQL SELECT query to pull back rows where Kessel scores
$query = "SELECT COUNT(*) FROM goals WHERE player_id = 4";
$response = mysql_query($query) or die(mysql_error());
?>
<?php
while($row= mysql_fetch_array($response));{
echo $row['COUNT(*)'];
// get the next row's details and loop to the top
}
?>
</body>
</html>
您是否收到任何错误? –
究竟是如何不工作? –