我将MySQL Query值存储在PHP变量中,但它不显示数据。 P.S:数据在MySQL表格列中可用。
<?php
$cmsca= mysql_query("SELECT SUM(qa_effort) FROM tbl_uat WHERE product='CAP'");
while ($cresulta = mysql_fetch_array ($cmsca))
$arra[0] = $cresulta[0];
echo $arra[0];
?>
我没有线索,上面的代码有什么问题?需要帮助!
此致
答案 0 :(得分:5)
试试这个
<?php
$cmsca= mysql_query("SELECT SUM(qa_effort) as sums FROM tbl_uat WHERE product='CAP'");
while ($cresulta = mysql_fetch_array($cmsca))
{
echo $cresulta['sums'];
}
?>
答案 1 :(得分:-1)
首先,不要使用mysql_query, - 不推荐使用,而是使用http://www.php.net/manual/en/mysqli.query.php。 接下来,在运行查询之前,您需要连接到db;
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$result = mysqli->query("SELECT SUM(qa_effort) as sums FROM tbl_uat WHERE product='CAP'");
while ($row = $result->fetch_array()) {
var_dump($row);
}
$mysqli->close();
?>
答案 2 :(得分:-1)
尝试这个怎么样:
<?php
$arra = array();
$cmsca= mysql_query("SELECT SUM(qa_effort) FROM tbl_uat WHERE product='CAP'");
while ($row = mysql_fetch_array ($cmsca))
$arra = $row;
print_r($arra);
?>