简体   繁体   English

PHP / MySQL Concat到单个列并更新表中的其他列

[英]PHP/MySQL Concat to a single column and Update other columns in table

Am trying to only concat new updates to column updates and UPDATE the values in the rest of the columns but I've hit bit of a snag that I can't seem to workout. 我试图只对列updates新的更新并更新其余列中的值,但我已经看到了一些我似乎无法锻炼的障碍。

My SQL looks like this: 我的SQL看起来像这样:

$query="Update tickets SET product='$product',
        p='$p',
        i='$i',
        summary='$summary',
        workaround='$workaround',
        concat(updates,'$additional_update'),
        status='$status',
        raised_by='$raised_by',
        updated_by_user='$updated_by' WHERE id='$id'";

the updates column is like a comments column, where new updates are meant to be appended to the existing text. updates列类似于注释列,其中新更新将附加到现有文本。

The error I'm getting on the web server: 我在网络服务器上得到的错误:

Update tickets SET product='T-Box', p='00000817766', i='-', summary='Testing update field
\r\nAdding an update\r\ntesting if null works for update', workaround='n/a', concat(updates,' ','test2@18:53:17:second update/n'), status='Open', raised_by='No', updated_by_user='test2' WHERE id='223'

Running the query directly in MySQL: 直接在MySQL中运行查询:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(updates,'test2@18:53:17:second update/n'), status='Open', raised_by='No', updat' at line 1

Help is much appreciated! 非常感谢帮助!

You need to specify where the value of this statement concat(updates,'$additional_update') to be set. 您需要指定要设置此语句concat(updates,'$additional_update')值的位置。

Update tickets 
SET    product = '$product',
       p = '$p',
       i = '$i',
       summary = '$summary',
       workaround = '$workaround',
       updates = CONCAT(updates,'$additional_update'),  // <== see this
       status = '$status',
       raised_by = '$raised_by',
       updated_by_user = '$updated_by' 
WHERE id = '$id'

try this: 尝试这个:

$query="Update tickets SET product='$product',
        p='$p',
        i='$i',
        summary='$summary',
        workaround='$workaround',
        updates=concat(updates,'$additional_update'),
        status='$status',
        raised_by='$raised_by',
        updated_by_user='$updated_by' WHERE id='$id'";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM