这是我的代码,我的错误是$ result变量应该是一个数组。但我不太清楚如何实现这一点。
<?php
$sql ="SELECT AVG(dive_rating) AS avg_rating,
AVG(col1) AS col1,
AVG(col2) AS col2,
AVG(col3) AS col3,
AVG(col4) AS col4,
FROM this_table WHERE col_name='$col_name'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$col1 = $row['col1'];
$col2 = $row['col2'];
$col3 = $row['col3'];
$col4 = $row['col4'];
$col5 = $row['col5'];
echo round($col1,1);
echo round($col2,1);
echo round($col3,1);
echo round($col3,1);
?>
答案 0 :(得分:2)
你有一个额外的逗号,请尝试这样:
$sql ="SELECT AVG(dive_rating) AS avg_rating,
AVG(col1) AS col1,
AVG(col2) AS col2,
AVG(col3) AS col3,
AVG(col4) AS col4
FROM this_table WHERE col_name='$col_name'";