Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Summing values in dynamic table columns

Community Beginner ,
Feb 24, 2009 Feb 24, 2009
I'm having some difficulty figuring out how to sum column values in dynamic tables. In other words, I have created a dynamic table (php/mysql). One column has a list of prices, and I need to sum the list of prices. I know this is pretty simple stuff. Can someone direct me to an example of the appropriate code?
TOPICS
Server side applications
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 24, 2009 Feb 24, 2009
LATEST
"firalivet" <webforumsuser@macromedia.com> wrote in message
news:go1j76$d4l$1@forums.macromedia.com...
> One column
> has a list of prices, and I need to sum the list of prices. I know
> this is
> pretty simple stuff.

There are several ways to do this, but a simple way is to create a
variable to hold a running total and add the current price to it when
you display each row. The following is a simplified example of the
code:

<?php $total = 0; ?>

<?>php do { // this is the start of the repeat region ?>
<tr><td><?php echo $row_recordsetName['price']; $total +=
$row_recordsetName['price']; ?></td></tr>
<?php } while ($row_recordsetName =
mysql_fetch_array($recordsetName)); // end of repeat region ?>

<tr><td><?php echo $total; ?></td></tr>

--
David Powers
Adobe Community Expert, Dreamweaver
http://foundationphp.com

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines