回答編集履歴

1

途中で送信したため

2017/05/31 04:02

投稿

kanimaru
kanimaru

スコア1013

test CHANGED
@@ -54,9 +54,23 @@
54
54
 
55
55
  // category_id が存在するかを判定し、存在した場合はPOSTデータのcategoryを
56
56
 
57
+   // 存在しなければ、空文字を $categorybox へ代入
58
+
57
59
  $categorybox = isset($_POST['category_id'])? $_POST['category']: '';
58
60
 
61
+ // $result で取得できたデータ数分 OPTION タグを生成
62
+
59
63
  while ($row = $result->fetch_assoc()) {
64
+
65
+ // OPTIONタグを生成
66
+
67
+ // OPTIONタグの属性valueに対して、当該ループ時のDBに登録されていた$rowのデータcategoryIDをセット
68
+
69
+   // もし、$categoryboxのデータと当該ループ時のDB登録されていた$rowのデータcategoryが一致した場合は、当該OPTIONタグを選択状態へ
70
+
71
+   //
72
+
73
+ // OPTIONタグのテキストノードに、当該ループ時のDBに登録されていた$rowのデータcategoryをセット
60
74
 
61
75
  echo "<option value='" .$row['category_id']."'".($row['category'] == $categorybox?'selected':'') .">".$row['category']."</option>";
62
76