请教: 从表中取出某字段信息,在原信息中添加若干内容,再写入原字段。
分成两步就是:
//取出
$result = mysql_query ( select 'infor' from 'table' where 'id' = 99 );
$result = $result['infor'] + "需要添加的内容" ;//更新
update `table` set `infor`= `infor`+ $result where 'id' = 99 ;
用一条语句执行,应该怎么写?
分成两步就是:
//取出
$result = mysql_query ( select 'infor' from 'table' where 'id' = 99 );
$result = $result['infor'] + "需要添加的内容" ;//更新
update `table` set `infor`= `infor`+ $result where 'id' = 99 ;
用一条语句执行,应该怎么写?
将参数连接成字符串返回。如果有任何一个参数为 NULL,返回值也为 NULL。可以有超过 2 个的参数。数字参数将被转换为相等价的字符串形式:
//大概是这句,首次插入,第二次是更新
insert into story (id,infor) values(99,'需要添加的内容') on duplicate key update set infor = concat(infor,'需要添加的内容') ;
//方法二
update `table` set `infor`= concat(infor,"需要添加的内容") where id= 99 ;
mysql> select * from tb1;
+----+------+
| id | str |
+----+------+
| 1 | abc |
+----+------+
1 row in set (0.00 sec)mysql> update tb1 set str=concat(str,'edf') where id = 1;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from tb1;
+----+--------+
| id | str |
+----+--------+
| 1 | abcedf |
+----+--------+
1 row in set (0.00 sec)mysql>