![](/img/trans.png)
[英]Can I have a column capable of keeping all types in MySQL (MariaDB)?
[英]How can i add a new entry into a mysql table, BUT only for 1 column, while keeping all other column data
所以我有下表
但是當我運行以下命令時:
"INSERT INTO default_db.loader_messages (confirmation_secure_radio_button_message) VALUES ('$confirmmessagevalue1')";
它添加了一個新行,但如上所示清空了 loader_message1 列。
請告訴我如何在 loader_message1 列中保留當前數據以及添加新行?
如果您可以從 insert..values 更改為 insert..select 那么您可以
drop table if exists t;
create table t (id int auto_increment primary key,col1 varchar(10),col2 varchar(10));
insert into t (col1) values ('col1');
insert into t (col1,col2)
select col1,'aaa'
from t where id = (select max(id) from t)
;
insert into t (col1) values ('xxx');
insert into t (col1,col2)
select col1,'bbb'
from t where id = (select max(id) from t)
;
select * from t;
+----+------+------+
| id | col1 | col2 |
+----+------+------+
| 1 | col1 | NULL |
| 2 | col1 | aaa |
| 3 | xxx | NULL |
| 4 | xxx | bbb |
+----+------+------+
4 rows in set (0.02 sec)
如果這對您來說是不可能的,那么請考慮在插入或插入過程之前在前端捕獲,並在插入后使用更新填充。
我提到將列值復制到多行是一個糟糕的設計。
還是……你要
select loader_message1 from dbname where yourcondition;
將 mysqli 結果放入 $row 然后使用
$row['loader_message1'] or $row[0]
在插入像
insert... (fld1, fld2) values (value1, value2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.