我知道$ wins应该是3.因为我在表“rated_teams”的“win”列中有3行,带有整数“1”但是由于某种原因,这段代码不起作用。你能找到问题吗?另外,我知道其中一些已被删除。我会更新整个页面,一旦我得到它至少在工作状态。
<?php
$sql = "SELECT SUM(win) FROM rated_teams WHERE server='$server' AND name='$myteam'";
$query = mysql_query($sql, $con)
or die('A error occured: ' . mysql_error());
while ((mysql_fetch_array($query))) {
$wins = $row['SUM(win)'];
}
?>
<h3>Total Wins: <?php echo $wins?> </h3>
答案 0 :(得分:2)
尝试
$sql = "SELECT SUM(win) as sum FROM rated_teams WHERE server='$server' AND name='$myteam'";
当你得到像
这样的时候while ($row = mysql_fetch_array($query)) {
$wins = $row['sum'];
}
我的建议是尽量避免使用mysql_*
函数,因为它们已被弃用。请使用mysqli_*
函数或PDO statements
。
答案 1 :(得分:0)
您没有设置$ row变量。编辑你的时间。
while ($row = mysql_fetch_array($query))
答案 2 :(得分:0)
您需要为计算列提供别名。试试这个:
<?php
$sql = "SELECT SUM(win) as sumwin FROM rated_teams WHERE server='$server' AND name='$myteam'";
$query = mysql_query($sql, $con) or die('A error occured: ' . mysql_error());
while ($row = mysql_fetch_array($query)) {
$wins = $row['sumwin'];
}
?>
<h3>Total Wins: <?php echo $wins?> </h3>
答案 3 :(得分:0)
请以正确的方式编写sql查询。写这样。
$sql = "SELECT SUM(win) as sumwin FROM rated_teams WHERE server='".$server."' AND name='".$myteam."'";
答案 4 :(得分:0)
while ((mysql_fetch_array($query))) {
应该是
while ($row = mysql_fetch_array($query) ) {