


In the same SQL table, PHP queries the sum of two columns of data and then outputs it.
//Calculate the sum of the order quantity
<code><span>$query_num</span> = <span>"SELECT SUM(order_num) from hcf_order_db where order_id = XXX"</span>; <span>$arr_qn</span> = mysqli_query(<span>$dbc</span>,<span>$query_num</span>); <span>list</span>(<span>$sum</span>)=mysqli_fetch_row(<span>$arr_qn</span>);</code>
//Calculate the sum of the order amount
<code><span>$query_amount</span> = <span>"SELECT SUM(order_amount) from hcf_order_db where order_id = XXX"</span>; <span>$arr_qm</span> = mysqli_query(<span>$dbc</span>,<span>$query_amount</span>); <span>list</span>(<span>$sum2</span>)=mysqli_fetch_row(<span>$arr_qm</span>);</code>
Then the PHP output:
<code><span><<span>td</span><span>class</span>=<span>'font-songti'</span><span>align</span>=<span>'center'</span>></span><span><span><?php</span><span>echo</span><span>$sum</span><span>?></span></span><span></<span>td</span>></span><span><<span>td</span><span>class</span>=<span>'font-cali'</span><span>align</span>=<span>'right'</span>></span><span><span><?php</span><span>echo</span><span>$sum2</span><span>?></span></span><span></<span>td</span>></span></code>
If the output number is followed by many decimal places, you can set the attribute of the value in SQL Set to DECIMAL(16,1).
The following 1 means retaining 1 decimal point.
The above introduces the same table in SQL, and PHP queries the sum of two columns of data and outputs it, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to Quickly View the Total of a Column in Excel If you just want to know the total of a column without adding that information to your spreadsheet, you can use the Excel status bar to quickly view the total of a column or any range of cells. To see the sum of a column using the Excel status bar: Highlight the data you want to summarize. To select an entire column, click the column name. Otherwise, drag cells to select your range. At the bottom of the screen, you'll see information about your selection, such as the average of all values and the number of data points in the range. You will also see the sum of all values in the selected cells. How to sum columns in Excel using AutoSum If you wish to add the sum of a column to a spreadsheet, there are many situations

When writing web applications using PHP, a MySQL database is often used to store data. PHP provides a way to interact with the MySQL database called MySQLi. However, sometimes when using MySQLi, you will encounter an error message, as shown below: PHPFatalerror:Calltoundefinedfunctionmysqli_connect() This error message means that PHP cannot find my

PDOPDO is an object-oriented database access abstraction layer that provides a unified interface for PHP, allowing you to use the same code to interact with different databases (such as Mysql, postgresql, oracle). PDO hides the complexity of underlying database connections and simplifies database operations. Advantages and Disadvantages Advantages: Unified interface, supports multiple databases, simplifies database operations, reduces development difficulty, provides prepared statements, improves security, supports transaction processing Disadvantages: performance may be slightly lower than native extensions, relies on external libraries, may increase overhead, demo code uses PDO Connect to mysql database: $db=newPDO("mysql:host=localhost;dbnam

Solution to php unable to connect to mysqli: 1. Open the "php.ini" file; 2. Find "mysqli.reconnect"; 3. Change "mysqli.reconnect = OFF" to "mysqli.reconnect = on".

If you encounter the following error message when using PHP to connect to a MySQL database: PHPWarning:mysqli_connect():(HY000/2002):Connectionrefused, then you can try to solve this problem by following the steps below. To confirm whether the MySQL service is running normally, you should first check whether the MySQL service is running normally. If the service is not running or fails to start, it may cause a connection refused error. you can

The running file of mysql is mysqld; mysqld is an executable file, which represents the Mysql server program. Executing this file can directly start a server process; and mysqld_safe is a startup script, which will indirectly call mysqld and also start a monitor. process.

In this article, we will show you how to reorder multiple columns in PowerQuery by dragging and dropping. Often, when importing data from various sources, columns may not be in the desired order. Reordering columns not only allows you to arrange them in a logical order that suits your analysis or reporting needs, it also improves the readability of your data and speeds up tasks such as filtering, sorting, and performing calculations. How to rearrange multiple columns in Excel? There are many ways to rearrange columns in Excel. You can simply select the column header and drag it to the desired location. However, this approach can become cumbersome when dealing with large tables with many columns. To rearrange columns more efficiently, you can use the enhanced query editor. Enhancing the query

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())
