php - 如何将一栏的内容复制到另一栏?

标签 php html mysql sql

我有以下表结构:

// Posts
+----+---------+-----------------+------------------+------------------------+------------------------+
| id |  title  |  content_html   | content_markdown |   content_edit_html    | content_edit_markdown  |
+----+---------+-----------------+------------------+------------------------+------------------------+
| 1  | title1  | <b>content1</b> | **content1**     | <b>content1_edited</b> | **content1_edited**    |
| 2  | title2  | <i>content2</i> | *content2*       |                        |                        |
+----+---------+-----------------+------------------+------------------------+------------------------+

如上表所示,我只保留最后两次编辑(content(html/markdown) 是最后一次编辑之前的一次或未经编辑的内容,content_edit(html/markdown) 是最后一次编辑,如果没有任何编辑则为空)

<小时/>

现在请看一下这两个示例:

示例一:我想编辑第一篇已编辑的帖子。这是新值:

**content1_new_value**

我还使用 PHP 库将其转换为 html 并制作:

<b>content1_new_value</b>

我想用 content_edit_(html/markdown) 的当前内容填充(更新)content_(html/markdown) 的内容,并填充(更新)此内容具有新值的 content_edit_(html/markdown) 列,如下所示:

+----+---------+------------------------+----------------------+----------------------------+------------------------+
| id |  title  |  content_html          | content_markdown     | content_edit_html          | content_edit_markdown  |
+----+---------+------------------------+----------------------+----------------------------+------------------------+
| 1  | title1  | <b>content1_edited</b> | **content1_edited**  | <b>content1_new_value</b>  | **content1_new_value** |
+----+---------+------------------------+----------------------+----------------------------+------------------------+
<小时/>

示例二:我想编辑第二个帖子尚未编辑。这是新值:

*content2_new_value*

我还使用 PHP 库将其转换为 html 并制作:

<i>content2_new_value</i>

在这种情况下,我想保持 content_(html/markdown) 完整(不做任何更改),只用新值更新 content_edited_(html/markdown) 等像这样:

+----+---------+-----------------+------------------+------------------------+--------------------------+
| id |  title  |  content_html   | content_markdown |   content_edit_html    | content_edit_markdown    |
+----+---------+-----------------+------------------+------------------------+--------------------------+
| 2  | title2  | <i>content2</i> | *content2*       | *content2_new_value*   | <i>content2_new_value</i>|
+----+---------+-----------------+------------------+------------------------+--------------------------+

正如你所见,我只保留了最后的两次编辑。我怎样才能做到这一点?

最佳答案

检查 CASE WHEN ELSE END

case  
when content_edit_html is not null
update table set content_html = content_edit_html, content_markdown = content_edit_markdown, 
content_edit_html = <b>content1_new_value</b>, content_edit_markdown = **content_new_value**
where id = 1
else
update table set content_edit_html = <b>content1_new_value</b>, content_edit_markdown = **content_new_value**
where id = 1
end

关于php - 如何将一栏的内容复制到另一栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36096227/

相关文章:

mysql - 在 SQL 中设置差异

PHP 7.4+ 类属性类型

javascript - HMVC Codeigniter 中没有 'Access-Control-Allow-Origin' 错误

javascript - 如何防止使用 JavaScript 或 jQuery 向上滚动?

html - 当我进入页面时无法将焦点设置到我的 <ion-input>

c# - 如何构造一个正确的MySQL连接串?

PHP include_once 在本地工作但调用 cron 不工作

javascript - 动态 HTML 内容页面,如 Dropbox 和 Soundcloud

jquery - 选项卡 - 突出显示事件选项卡

python - 安装 mysql