RE: [PHP] need help with PHP/MySQL
| From: | Gustavo Souza | Date: | Tue, 21 Nov 2000 04:44:53 +0000 |
| Subject: | RE: [PHP] need help with PHP/MySQL | ||
| References: | 1 | Groups: | php.db php.general |
| Request: | Send a blank email to php-general+get-26392@lists.php.net to get a copy of this message | ||
SELECT SUM() dont work for me cause the fields have (R$) 300.00
and not only the numbers ....
i need to do it on php ...
thanks
GS
At 14:39 21/11/2000 +1000, you wrote:
Instead of all this, you should have SQL perform the SUM for you. "SELECT SUM(preco) from preco" This will sum all rows in the 'preco' table. You should put a where clause in if you want to only sum some of the rows. -----Original Message----- From: Gustavo Souza [mailto:gus74@terra.com.br] Sent: Tuesday, 21 November 2000 14:28 To: php-general@lists.php.net Subject: [PHP] need help with PHP/MySQL oks, this code works for what i was looking for : $mysql = mysql_connect("host", "user", "pass"); mysql_select_db(teste); $sqlquery = "SELECT * FROM preco"; if ($resultset = mysql_query($sqlquery, $mysql)) { echo "<TABLE>"; while ($row = mysql_fetch_array($resultset)) { /* Remove R$ from Preco field */ $fullprice = ($row[preco]); $price = substr ("$fullprice", 3); $totalprice += ($price); } echo "<TR><TD>Total:</TD>"."<TD>".sprintf('%0.2f', $totalprice)."</TD>"."</TABLE>"; } but this code just calculate the sum fom one row .. how can i calculate the all rows from a table ... thanks GS