R
R
Roman2015-11-06 23:45:43
PHP
Roman, 2015-11-06 23:45:43

How to store math expressions in a MySQL table and then do calculations with PHP?

I need to store mathematical expressions in which field for each record in the table, and then sum them up using PHP
. For example,
ID| Title |Expression
where Expression can take the values ​​+1, -2, +5, -6 , that is, valid operands are [-,+]Integer. The task then to summarize these values ​​with grouping.
The first thing that comes in is a VARCHAR[8] field, that is, as a string.
1. Is there a more beautiful solution for storing mathematical operations in a table?
2. How then to sum up the field values ​​beautifully using PHP or SQL?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Taratin, 2015-11-06
@Taraflex

www.w3schools.com/sql/sql_func_sum.asp
Store simply as signed integers.

K
KorsaR-ZN, 2015-11-06
@KorsaR-ZN

If the expression can only be strictly formatted as you wrote (-|+[0-9]), then why did signed int not suit you? `), or I misunderstood something...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question