Forums
This topic is locked
How to create total of multiple raw
Posted 16 Aug 2006 23:17:28
1
has voted
16 Aug 2006 23:17:28 Rise Ristrict posted:
Hi everyone, I try to create some thing look this by dreamweaver using php,<b>
Product Name------Qtn-----Price------Total</b>
Keyboard------------5------10.00------50.00
Mouse---------------2------05.00------10.00
Headphone---------3------ 15.00------35.00
<b>_______________________Total----<font color=red>95.00</font id=red></b>
I done all but, My problem is, how can I create <b>Total</b>??
Pls help me..
Replies
Replied 17 Aug 2006 09:19:12
17 Aug 2006 09:19:12 Roddy Dairion replied:
I guess you're not doing the total within the query itself. If you're not then try to modify this script so that it fits on you page.
within the while loop insert this
$amount += sprintf("%0.2f", $row['fieldname for total of each']);
hope it helps.
within the while loop insert this
$amount += sprintf("%0.2f", $row['fieldname for total of each']);
hope it helps.
Replied 17 Aug 2006 21:46:33
17 Aug 2006 21:46:33 Rise Ristrict replied:
thanks <b>Roddy Dairion</b>, i will reply after I try it now!!
Replied 19 Aug 2006 09:11:55
19 Aug 2006 09:11:55 Rise Ristrict replied:
This won't work
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
$amount += sprintf("%0.2f", $row['fieldname for total of each']);
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
I find a solution, I create a new recordset called "id_total" with sum sql like this 'SELECT sum(chc_pages.id) AS sum_id_1 FROM chc_pages '
Field explanation
chc_pages = table name
id = field name of that i want to create total.
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
mysql_select_db($database_dbase, $dbase);
$query_id_total = "SELECT sum(chc_pages.id) AS sum_id_1 FROM chc_pages ";
$id_total = mysql_query($query_id_total, $dbase) or die(mysql_error());
$row_id_total = mysql_fetch_assoc($id_total);
$totalRows_id_total = mysql_num_rows($id_total);
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
then insert into page
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
echo $row_id_total['sum_id_1'];
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Edited by - Sun123 on 19 Aug 2006 09:13:45
Edited by - Sun123 on 19 Aug 2006 09:15:45
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
$amount += sprintf("%0.2f", $row['fieldname for total of each']);
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
I find a solution, I create a new recordset called "id_total" with sum sql like this 'SELECT sum(chc_pages.id) AS sum_id_1 FROM chc_pages '
Field explanation
chc_pages = table name
id = field name of that i want to create total.
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
mysql_select_db($database_dbase, $dbase);
$query_id_total = "SELECT sum(chc_pages.id) AS sum_id_1 FROM chc_pages ";
$id_total = mysql_query($query_id_total, $dbase) or die(mysql_error());
$row_id_total = mysql_fetch_assoc($id_total);
$totalRows_id_total = mysql_num_rows($id_total);
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
then insert into page
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
echo $row_id_total['sum_id_1'];
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Edited by - Sun123 on 19 Aug 2006 09:13:45
Edited by - Sun123 on 19 Aug 2006 09:15:45