Cibiņš Posted December 29, 2012 Report Share Posted December 29, 2012 Nesaprotu kā lai sasummē visu kopā kolonna 1 = daudzums;kolonna2 = cena; Respektīvi katrā rindā tik daudz kā katru rindas ieraksta cenu atsevišķi sasummēt māku bet kad jāsasummē visas cenas kopā tad dzen mistiskus ciparus. Kā lai atrisina šo problēmu? while ($rowprc = mysql_fetch_assoc($priceresult)) { $prc_price=$rowprc['price']; $prc_count=$rowprc['count']; $prc_price=mysql_real_escape_string($prc_price); $prc_count=mysql_real_escape_string($prc_count); $prc_price=stripslashes($prc_price); $prc_count=stripslashes($prc_count); $totalprice = $prc_price * $prc_count; $order_price = number_format($totalprice, 2, '.', ''); } Link to comment Share on other sites More sharing options...
daGrevis Posted December 29, 2012 Report Share Posted December 29, 2012 `SELECT SUM(kolona1, kolona2) FROM tabula;` Link to comment Share on other sites More sharing options...
Cibiņš Posted December 29, 2012 Author Report Share Posted December 29, 2012 Te jau ir runa par sareizināšanu visupirms un tikai pēc tam dzen to $total Respektīvi vienā kolonnā ir cena, otrā - daudzums. Tātad visupirms $totalprice = $prc_price*$prc_count; Un tikai pēc tam summē visas cenas kopā iepriekš sareizinot ar daudzumu. Tik nemāku sasummēt to VISU produktu cenu kas iepriekš reizināti ar daudzumu. :( Link to comment Share on other sites More sharing options...
yancho Posted December 29, 2012 Report Share Posted December 29, 2012 SELECT SUM (`price` * `count`) FROM `table`; Link to comment Share on other sites More sharing options...
Cibiņš Posted December 29, 2012 Author Report Share Posted December 29, 2012 Dohh viens šits pēc otra.. :/ $priceresult = mysql_query("SELECT SUM (`order_prod_price * order_prod_count`) FROM `orders_detail` WHERE order_identificator = '$order_id'"); while ($rowprc = mysql_fetch_assoc($priceresult)) { $prc_price=$rowprc['order_prod_price']; $prc_count=$rowprc['order_prod_count']; $prc_price=mysql_real_escape_string($prc_price); $prc_count=mysql_real_escape_string($prc_count); $prc_price=stripslashes($prc_price); $prc_count=stripslashes($prc_count); } $order_price = number_format($prc_price, 2, '.', ''); izmet Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\pagetpath\list.php on line 120 120. līnija ir while ($rowprc = mysql_fetch_assoc($priceresult)) { Link to comment Share on other sites More sharing options...
yancho Posted December 29, 2012 Report Share Posted December 29, 2012 Vispār jau tur vēl ir problēma - mēs abi duraki, gan es, gan Cibiņš, es, jo SUM ir funkcija un pirms iekavām atstarpe nav pieļaujauma, precīzi būtu: SUM(`price` * `count`) Savukārt, Cibiņš nepareizi lieto `, šādi (`order_prod_price * order_prod_count`) SQL saprot, ka kollonas nosaukums ir "order_prod_price * order_prod_count"! Precīzi ir SUM(`order_prod_price` * `order_prod_count`) Bet izskatās, ka Cibiņam nav skaidrs kāpēc vispār ` tiek lietots. Link to comment Share on other sites More sharing options...
daGrevis Posted December 29, 2012 Report Share Posted December 29, 2012 Es domāju, ka Cibiņam ne tikai tas nav skaidrs... :D Link to comment Share on other sites More sharing options...
Cibiņš Posted December 29, 2012 Author Report Share Posted December 29, 2012 Done. I`m not nigga :D while ($rowprc = mysql_fetch_assoc($prcqr)) { $prc_price=$rowprc['SUM(order_prod_price * order_prod_count)']; $prc_count=$rowprc['order_prod_count']; $prc_price=mysql_real_escape_string($prc_price); $prc_count=mysql_real_escape_string($prc_count); $prc_price=stripslashes($prc_price); $prc_count=stripslashes($prc_count); } $order_price = number_format($prc_price, 2, '.', ''); Link to comment Share on other sites More sharing options...
daGrevis Posted December 29, 2012 Report Share Posted December 29, 2012 Tas strādā? Link to comment Share on other sites More sharing options...
Cibiņš Posted December 29, 2012 Author Report Share Posted December 29, 2012 Jap var klapīt topiku ciet. Viss čikiniekā. Nav astronomiskas summas vairs :D Link to comment Share on other sites More sharing options...
daGrevis Posted December 29, 2012 Report Share Posted December 29, 2012 Vari parādīt kodu kas ir pirms cikla? Link to comment Share on other sites More sharing options...
Cibiņš Posted December 29, 2012 Author Report Share Posted December 29, 2012 $prcqr = mysql_query("SELECT SUM(order_prod_price * order_prod_count) FROM orders_detail WHERE order_identificator = '".$order_id."'"); while ($rowprc = mysql_fetch_assoc($prcqr)) { $prc_price=$rowprc['SUM(order_prod_price * order_prod_count)']; $prc_count=$rowprc['order_prod_count']; $prc_price=mysql_real_escape_string($prc_price); $prc_count=mysql_real_escape_string($prc_count); $prc_price=stripslashes($prc_price); $prc_count=stripslashes($prc_count); } $order_price = number_format($prc_price, 2, '.', ''); Link to comment Share on other sites More sharing options...
renathy Posted December 29, 2012 Report Share Posted December 29, 2012 Šī rindiņa: $prc_count=$rowprc['order_prod_count']; arī strādā? Link to comment Share on other sites More sharing options...
Cibiņš Posted December 29, 2012 Author Report Share Posted December 29, 2012 $prc_count=$rowprc['order_prod_count']; Tas poh izņēmu ārā jo viņu vairs nevajag. Link to comment Share on other sites More sharing options...
aaxc Posted January 2, 2013 Report Share Posted January 2, 2013 /closed Link to comment Share on other sites More sharing options...
Recommended Posts