• We just launched and are currently in beta. Join us as we build and grow the community.

Total Sum in a Column using PHP/MySQL

omuyap

Recurring Revenue Specialist
O Rep
0
0
0
Rep
0
O Vouches
0
0
0
Vouches
0
Posts
167
Likes
148
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this tutorial, we are going to create Total Sum in a Column using PHP/MySQL. This simple work created to teach the user on how to calculate the values of a column using the SUM function to the PHP query. If you want to create a simple system like a point of sale, you can put this simple function to your project. You can also check the live demo of this simple tutorial, so you can get an idea and you can try this out, let's start coding.

⚙ Live Demo

Sample Source Code

  1. <?php
  2. $result1 =

    mysql_query(

    "SELECT sum(qty) FROM product"

    )

    or die(

    mysql_error(

    )

    )

    ;
  3. while (

    $rows1 =

    mysql_fetch_array(

    $result1)

    )

    {
  4. ?>
  5. <div

    class

    =

    "pull-left"

    >
  6. <div

    class

    =

    "span"

    ><div

    class

    =

    "alert alert-danger"

    ><i

    class

    =

    "icon-credit-card icon-large"

    ></

    i

    >

    Total number of Items:
  7. <b

    style

    =

    "color:red; font-size:18px;"

    ><?php echo $rows1[

    'sum(qty)'

    ]

    ; ?></

    b

    ></

    div

    ></

    div

    >
  8. </

    div

    >
  9. <?php }
  10. ?>

  11. <?php
  12. $result =

    mysql_query(

    "SELECT sum(amount) FROM product"

    )

    or die(

    mysql_error(

    )

    )

    ;
  13. while (

    $rows =

    mysql_fetch_array(

    $result)

    )

    {
  14. ?>
  15. <div

    class

    =

    "pull-left"

    >
  16. <div

    class

    =

    "span"

    ><div

    class

    =

    "alert alert-danger"

    ><i

    class

    =

    "icon-credit-card icon-large"

    ></

    i

    >

    Total Amount:
  17. <b

    style

    =

    "color:red; font-size:18px;"

    ><?php echo $rows[

    'sum(amount)'

    ]

    ; ?></

    b

    ></

    div

    ></

    div

    >
  18. </

    div

    >
  19. <?php }
  20. ?>

Output

untitled_21.jpg


⚙ Live Demo

Hope that this simple yet useful tutorial that I created may help you to your future projects.

If you are interested in programming, we have an example of programs that may help you even just in small ways.

Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,891

323,899

Top