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>
您是否收到任何錯誤? –
究竟是如何不工作? –