簡體   English   中英

如何通過換行獲取字段中的值並更新到php mysql中具有相同ID的表中的列?

[英]How to get the value in field by new line and update into the column in table with same id in php mysql?

我想問問如何獲取該列的值並更新為具有相同ID的另一列..此數據來自電子郵件管道,我想分離正文的值並更新為費用,凈額和毛額字段。

我希望你能幫助我。.謝謝

+------+---------+--------------------+---------+----------+-------+----------+
| id   | subject | body               | expense |   net    | gross | email    |
+------+---------+--------------------+---------+----------+-------+----------+
|  1   | Sales   | Expense = 2000     |    0    |    0     |   0   | ex@ex.com|
|      |         | netIncome = 5000   |         |          |       |          | 
|      |         | Gross    = 10000   |         |          |       |          |
+------+---------+--------------------+---------+----------+-------+----------+

假設您有一個\\n換行符,並且body具有相同的樣式,那么我們可以得到以下內容

mysql> select * from test \G
*************************** 1. row ***************************
  id: 1
body: Expense = 2000
netIncome = 5000
Gross    = 10000

現在要獲取每個金額,我們可以使用substring_index作為

mysql> select 
substring_index(substring_index(body,'=',-3),'\n',1) as expense, 
substring_index(substring_index(body,'=',-2),'\n',1) as netincome, 
substring_index(body,'=',-1) as gross from test;
+---------+-----------+--------+
| expense | netincome | gross  |
+---------+-----------+--------+
|  2000   |  5000     |  10000 |
+---------+-----------+--------+

所以對於更新它可能是

update your_table
set 
expense = substring_index(substring_index(body,'=',-3),'\n',1),
net = substring_index(substring_index(body,'=',-2),'\n',1),
gross = substring_index(body,'=',-1) ;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM