2016-04-22 13 views
-3
$nstkquty=$db->execute("SELECT (SUM(p.quantity) - SUM(s.quantity) - 
           SUM(o.quantity) - SUM(pr.quantity)) AS totalquty 
         FROM master_purchase AS p, product_sales AS s, 
          orders_details AS o, purchase_return AS pr 
         WHERE p.product_code='" . $cod . "' && 
           s.prd_code='" . $cod . "' && 
           o.prd_code='" . $cod . "' && 
           pr.product_code='" . $cod . "'"); 
$nwrquty = $nstkquty->fetch_assoc(); 
$data['avalqty'] = $nwrquty[0] ['SUM(totalquty)']; //$total_stkqty; 
echo json_encode($data); 
exit(); 

ここに私のコードは表示されず、エラーも表示されず、警告も表示されません。いずれにせよ、私はこの問題を解決するのに役立ちます。複数テーブルの合計mysqlの問題

+2

あなたも、任意のSQLクライアントにそのクエリを使用してみました:

$nstkquty=$db->execute("SELECT (sum(if(p.quantity is null, 0, p.quantity)) - sum(if(s.quantity is null, 0, s.quantity)) - sum(if(o.quantity is null, 0, o.quantity)) - sum(if(pr.quantity is null, 0, pr.quantity))) AS totalquty FROM master_purchase AS p, product_sales AS s, orders_details AS o, purchase_return AS pr WHERE p.product_code='" . $cod . "' && s.prd_code='" . $cod . "' && o.prd_code='" . $cod . "' && pr.product_code='" . $cod . "'"); 

はまたにこの行を更新しますか? – Mayday

+0

totalquty = NULL – Dasans

+0

'echo" SELECT(SUM(p.quantity)-SUM(s.quantity)-SUM(o.quantity)-SUM(pr.quantity))AS totalquty FROM master_purchase AS p、product_sales AS、orders_details '&& s.prd_code =' "。$ cod。" '&& o.prd_code =' "。$ cod。" '&& pr.product_code =' "と入力すると、 '' ')); "' 'とphpmyadminで試してエラーをチェックしてください。 –

答えて

0

未使用 $ data ['avalqty'] = $ nwrquty [0] ['SUM(totalquty)'];

同様に使用 $ data ['avalqty'] = $ nwrquty [0] ['totalquty'];

+0

申し訳ありません、結果はありません – Dasans

0

クエリを更新します。

$data['avalqty'] = $nwrquty[0] ['totalquty']; //$total_stkqty; 
+0

ごめんなさい – Dasans

+0

結果は? mysqlは直接 –

+0

結果は:totalquty NULL – Dasans

関連する問題