gloops100
gloops100

Reputation: 159

Store result of SQL query in PHP $variable

I want to save the result of my query (result of sum of all lines for 1 column) in PHP variable.
Example of my table :

CONSO_1 | CONSO_2
  15    |   10
  25    |    2
  54    |   45
  ..    |   ..

I want to sum all lines for CONSO_1 and * 12. Normally my query is OK.

But I want to store the result (here : (15+25+54)*12= 1128) in PHP $variable.

My query :

$query = "Select SUM(CONSO_1) * 12 AS CONSO_Total_1, SUM(CONSO_2) * 25 FROM test WHERE DATE_FORMAT(datetime,'%Y-%m-%d')=DATE(NOW())";

Can you help me please ?

Upvotes: 0

Views: 1578

Answers (1)

napendra
napendra

Reputation: 378

use this query and store result in a var

$query = "SELECT SUM(CONSO_1) FROM table_name";

This will return the sum of all values from CONSO_1 col.

Upvotes: 1

Related Questions