2016-03-19 10 views
0

私はテーブルの構造を以下している:あなたは上記の表に見たよう1つの列の内容を別の列にコピーするにはどうすればよいですか?

// 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)があれば最後の編集または空である(2本の最後の編集を続けます

例1::任意の編集は今この2つの例を見てみてください


)がない私が最初に編集したいです投稿がすでに編集されています。ここでは、新しい値は次のとおりです。

**content1_new_value** 

まあ、私もそれがPHPのライブラリを使用して、HTMLおよびこれを作るために変換します。

<b>content1_new_value</b> 

私は(更新)を記入したいの現在の内容とcontent_(html/markdown)の内容は、このようなcontent_edit_(html/markdown)とfill(更新)新しい値でこのコラム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** | 
+----+---------+------------------------+----------------------+----------------------------+------------------------+ 

例2:が編集されていない2番目の投稿を編集します。ただこの場合、

<i>content2_new_value</i> 

私は(変更なし)そのままcontent_(html/markdown)を維持したいと:まあ、私もそれがPHPのライブラリを使用して、HTML、これ作るために変換

*content2_new_value* 

:ここに新しい値があります新しい値で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>| 
+----+---------+-----------------+------------------+------------------------+--------------------------+ 

ご覧のように、私はちょうど2本の最後の編集を続けます。どうやってやるの?

答えて

2

チェックCASE 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 
+0

@stack答えはあなたの問題を解決した場合、あなたは正しいとしてもマークする必要があります。 – xpy

関連する問題