Php 我需要在volving COUNT(*)中以HTML显示一个MYSQL查询
我需要用php从mysql数据库获取查询结果。我到处找了找,我想我的东西应该有用,但没有。我在正确的文件夹中运行它。如果有任何其他人能告诉我的话,我将不胜感激 谢谢 这是我的密码Php 我需要在volving COUNT(*)中以HTML显示一个MYSQL查询,php,mysql,html,count,Php,Mysql,Html,Count,我需要用php从mysql数据库获取查询结果。我到处找了找,我想我的东西应该有用,但没有。我在正确的文件夹中运行它。如果有任何其他人能告诉我的话,我将不胜感激 谢谢 这是我的密码 <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <?php // define DB connection variables $host =
<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>
这里有一个错误:
while($row= mysql_fetch_array($response));{
事实上,分号在while之后,在{
之前(它不应该在那里)
无论如何,由于您只检索一个字段,而while则毫无用处。请将其删除,然后执行以下操作:
$query = "SELECT COUNT(*) as Count FROM goals WHERE player_id = 4";
$response = mysql_query($query) or die(mysql_error());
$row= mysql_fetch_array($response);
echo $row['Count'];
这里有一个错误:
while($row= mysql_fetch_array($response));{
事实上,分号在while之后,在{
之前(它不应该在那里)
无论如何,由于您只检索一个字段,而while则毫无用处。请将其删除,然后执行以下操作:
$query = "SELECT COUNT(*) as Count FROM goals WHERE player_id = 4";
$response = mysql_query($query) or die(mysql_error());
$row= mysql_fetch_array($response);
echo $row['Count'];
你收到任何错误吗?这到底是怎么回事?你收到任何错误吗?这到底是怎么回事?谢谢你的帮助。它解决了我的问题。我感谢你的帮助!谢谢你的帮助。它解决了我的问题。我感谢你的帮助!