teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

※コメントいただいた点を更新しました。xxx部は製品名となります。製品名を配列でSQLに格納し、更新するために読み出した際にまたチェックボックスで表示(さらに更新)出来るようにしたいです

2018/10/22 10:33

投稿

black_onion
black_onion

スコア7

title CHANGED
File without changes
body CHANGED
@@ -7,12 +7,13 @@
7
7
  配列以外のデータはテキストで表示されているので問題ないとは思うのですが、、、
8
8
  SQLからのデータを配列として見られていないのか、そもそも配列として認識されていないのか、はたまた別理由なのか見当が付きません。
9
9
  ご指導いただければと思います。
10
+
10
11
  ```PHP
11
12
  //MySQLデータベースに接続する
12
13
  $pdo = new PDO($dsn, $user, $password);
13
14
  $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
14
15
  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15
- $sql = "SELECT * FROM xxxx WHERE id LIKE(:id)";
16
+ $sql = "SELECT * FROM データベース名 WHERE id LIKE(:id)";
16
17
  $stm = $pdo->prepare($sql);
17
18
  $stm->bindValue(':id', "{$id}", PDO::PARAM_STR);
18
19
  $stm->execute();
@@ -22,7 +23,7 @@
22
23
  **********************
23
24
  if (isSet($row["productarry"])){
24
25
  // 「product」かどうか確認する
25
- $product = ['xxxx','xxxx','xxxx','xxxx','xxxx'];
26
+ $product = ['製品A','製品B','製品C','製品D','製品E'];
26
27
  $diffValue = array_diff($row["productarry"], $product);
27
28
  // 規定外の値が含まれていなければOK
28
29
  if (count($diffValue)==0){
@@ -35,11 +36,11 @@
35
36
 
36
37
 
37
38
  echo "<div class='form-group'>", "<div class='col-lg-8'>", "<div class='checkbox' id='product'>", "<h4>", "Product Type", "</h4>",
38
- "<label>", "<input type='checkbox' name='productarry[]' value='xxxx' $productarry", "xxxx", "</label>", "<span style='margin-right: 25px;'>", "</span>",
39
+ "<label>", "<input type='checkbox' name='productarry[]' value='製品A' $productarry", "製品A", "</label>", "<span style='margin-right: 25px;'>", "</span>",
39
- "<label>", "<input type='checkbox' name='productarry[]' value='xxxx' > $productarry", "xxxx", "</label>", "<span style='margin-right: 25px;'>", "</span>",
40
+ "<label>", "<input type='checkbox' name='productarry[]' value='製品B' > $productarry", "製品B", "</label>", "<span style='margin-right: 25px;'>", "</span>",
40
- "<label>", "<input type='checkbox' name='productarry[]' value='xxxx' > $productarry ", "xxxx", "</label>", "<span style='margin-right: 25px;'>", "</span>",
41
+ "<label>", "<input type='checkbox' name='productarry[]' value='製品C' > $productarry ", "製品C", "</label>", "<span style='margin-right: 25px;'>", "</span>",
41
- "<label>", "<input type='checkbox' name='productarry[]' value='xxxx' > $productarry", "xxxx", "</label>", "<span style='margin-right: 25px;'>", "</span>",
42
+ "<label>", "<input type='checkbox' name='productarry[]' value='製品D' > $productarry", "製品D", "</label>", "<span style='margin-right: 25px;'>", "</span>",
42
- "<label>", "<input type='checkbox' name='productarry[]' value='xxxx' > $productarry", "xxxx", "</label>", "<span style='margin-right: 25px;'>", "</span>",
43
+ "<label>", "<input type='checkbox' name='productarry[]' value='製品E' > $productarry", "製品E", "</label>", "<span style='margin-right: 25px;'>", "</span>",
43
44
  "<br>",
44
45
  "<br>",
45
46
  "</div>",