1

I am storing MySQL Query value in PHP variable, but its not displaying data. P.S: Data is available in MySQL table column.

 <?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];
?>

I am out of clues, what is wrong in above code? Need help!

Regards

3
  • 1
    have you tried using var_dump($cresulta[0]); to see what's in there ? Sometimes echo fail displaying some values (like false) Commented Oct 9, 2013 at 10:59
  • 2
    Please make sure your query returns the result, otherwise you are doing right. Commented Oct 9, 2013 at 11:00
  • do: var_dump($cresulta) inside while loop Commented Oct 9, 2013 at 11:06

3 Answers 3

5

try this

   <?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'];
   }
  ?>
Sign up to request clarification or add additional context in comments.

2 Comments

Answer is ok but explanation makes a answer better +1.
@Farhad the reality is i dont know what to explain :) , this basic, he is mixing between mysql_fetch_array and mysql_fetch_num .
-1

first of all, do not use mysql_query, - it's deprecated, use http://www.php.net/manual/en/mysqli.query.php instead. Next, you need to connect to the db, before running query;

$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();
?>

Comments

-1

How about trying this:

<?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);
 ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.