How to Sum Column in MySQL using PHP/MySQL PHP Script
In this tutorial, I’m going to show you how to sum MySQL column using PHP/MySQLi. I’ve also included in this tutorial the use of GROUP BY in mysqli query and the 2 mysqli methods which I have included in the comments. This tutorial does not include a good design but will give you idea on the topic.
Creating our Database
Table of Contents
First, we’re going to create our database.
1. Open phpMyAdmin.
2. Click databases, create a database and name it as “sum”.
3. After creating a database, click the SQL and paste the below codes. See image below for detailed instruction.
-
CREATE TABLE `product` (
-
`productid` INT(11) NOT NULL AUTO_INCREMENT,
-
`product_name` VARCHAR(30) NOT NULL,
-
PRIMARY KEY(`productid`)
-
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-
CREATE TABLE `sales` (
-
`salesid` INT(11) NOT NULL AUTO_INCREMENT,
-
`productid` INT(11) NOT NULL,
-
`sales_qty` DOUBLE NOT NULL,
-
PRIMARY KEY(`salesid`)
-
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Learn How to install How to Sum Column in MySQL using PHP/MySQL PHP Script?