简体   繁体   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?

i want to ask how to get the value of the column and update into another column with same id.. this data came from email piping and i want to separate the value of the body and update into the expense , net and gross field.. 我想问问如何获取该列的值并更新为具有相同ID的另一列..此数据来自电子邮件管道,我想分离正文的值并更新为费用,净额和毛额字段。

i hope you can help me guys.. thank you 我希望你能帮助我。.谢谢

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

Assuming that you have one \\n for the line break and having the same pattern for the body , lets say we have the following 假设您有一个\\n换行符,并且body具有相同的样式,那么我们可以得到以下内容

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

Now to get each amount we can use substring_index something as 现在要获取每个金额,我们可以使用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 |
+---------+-----------+--------+

So for the update it could be as 所以对于更新它可能是

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.

相关问题 如何在列中拆分或获取值并在同一表的另一列中更新? PHP的MySQL - How to split or get the value in column and update in another column in same table? php mysql 如何在与mysql中的旧值具有相同ID的列中插入新值 - how to insert new value in column with same id with old value in mysql 如果返回 True mysql php,如何查询唯一值并更新同一表中的另一个字段 - How Can I Query for Unique Value and Update another Field in Same Table If return True mysql php php mysql用同一字段更新多个表? - php mysql update multiple table with same field? PHP变量值不更新MySQL表字段? - PHP variable value to NOT update MySQL table field? 从MySQL表的一列获取字符串值,并更新同一行的另一列值 - Get string value from one column of MySQL Table and update its other column value of same row MySQL/PHP 如何从与同一行的另一个字段相关的字段中获取特定字段 id - MySQL/PHP how to get specific field id from field which is related with another field of the same row 如何在php中插入mysql的自动递增字段ID,并将一个表的ID更新为另一个表? - How to insert the auto incremented field id of mysql in php and update the id of one table to another? 根据用户 id 从表中更新 Mysql 列字段 - Update Mysql column field from a table based on user id 如何借助mysql表中的id值回显其他字段(列)值 - How to echo other field (column) value with the help of id value from mysql table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM