Mysql query in php is not getting the desire output?

Hi, i’m not getting 0 as a result, where there is no value of qty*ctnqty, it’s only giving me the value of qty*ctnqty, where there have some value.

Please help!

$detailships = "SELECT COALESCE(SUM(qty*ctnqty),0) AS total 
FROM freddyshipment 
WHERE kcgmt='$posrefno' 
AND style='$postyle'
AND orderno='$posorderno'
AND col='$poscol'
AND sizes='$posize'
GROUP BY kcgmt,style,orderno,col,sizes";

}
$details_resultships = mysqli_query($conn,$detailships)
    or die ( "Couldn't get Products: ".mysqli_error($conn) );
while ( $new_row = mysqli_fetch_array ( $details_resultships ) )
{

echo "<td class=count-me>".$new_row[ 'total' ]."</td>";

}


Hi @mehidy1437 and welcome to the forum.

Try printing the SQL $detailship statement to the screen then copy and paste the query into PhpMyAdmin.

Edit:
If PhpMyAdmin is not available the try the following:

echo '<pre>'; // formats result by adding linefeeds
  print_r( $new_row );
echo '</pre>';
die; // stop further output

Hi, here below is the result, giving result of total.

Array
(
[0] => 140
[total] => 140
)

Well here’s the simple answer: The database doesnt invent data.
So try running this:

"SELECT * 
FROM freddyshipment 
WHERE kcgmt='$posrefno' 
AND style='$postyle'
AND orderno='$posorderno'
AND col='$poscol'
AND sizes='$posize'

and see what results you get back before grouping and multiplying and all of that. Clearly, there IS a value of qty*ctnqty in your data.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.