1

我将 MySQL Query 值存储在 PHP 变量中,但它不显示数据。PS:数据在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];
?>

我没有线索,上面的代码有什么问题?需要帮忙!

问候

4

3 回答 3

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'];
   }
  ?>
于 2013-10-09T10:58:46.983 回答
-1

首先,不要使用 mysql_query, - 它已被弃用,请改用http://www.php.net/manual/en/mysqli.query.php。接下来,您需要在运行查询之前连接到数据库;

$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();
?>
于 2013-10-09T11:03:41.333 回答
-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);
 ?>
于 2013-10-09T11:04:12.350 回答