回答編集履歴
6
調整
answer
CHANGED
@@ -56,4 +56,50 @@
|
|
56
56
|
$checked=(in_array($val,$data)!==false)?" checked":"";
|
57
57
|
echo "<label><input type='checkbox' name='productarry[]' value='{$val}'{$checked}>{$val}</label><span style='margin-right: 25px;'></span>\n";
|
58
58
|
}
|
59
|
+
```
|
60
|
+
|
61
|
+
# idをpostで渡す
|
62
|
+
```PHP
|
63
|
+
<?PHP
|
64
|
+
$rows=[];
|
65
|
+
$id=filter_input(INPUT_POST,"id");
|
66
|
+
$data=[];
|
67
|
+
$product = ['製品A','製品B','製品C','製品D','製品E'];
|
68
|
+
try{
|
69
|
+
$sql = "SELECT productarry FROM tbl where 1 ";
|
70
|
+
if(!is_null($id) and $id!==false){
|
71
|
+
$sql.= "and id=? ";
|
72
|
+
array_push($data,$id);
|
73
|
+
}
|
74
|
+
$sql.= "and productarry in('".implode("','",$product)."') ";
|
75
|
+
print $sql;//debug
|
76
|
+
print_r($data);
|
77
|
+
//$stm = $pdo->prepare($sql);
|
78
|
+
//$stm->execute($data);
|
79
|
+
//$rows = $stm->fetchAll(PDO::FETCH_ASSOC);
|
80
|
+
}catch(PDOException $e){
|
81
|
+
die($e->getMessage());
|
82
|
+
}
|
83
|
+
$data=array_map(function($x){return $x["productarry"];},$rows);
|
84
|
+
echo <<<eof
|
85
|
+
<div class='form-group'>
|
86
|
+
<div class='col-lg-8'>
|
87
|
+
<div class='checkbox' id='product'>
|
88
|
+
<h4>Product Type</h4>
|
89
|
+
eof;
|
90
|
+
foreach ($product as $val) {
|
91
|
+
$checked=(in_array($val,$data)!==false)?" checked":"";
|
92
|
+
echo "<label><input type='checkbox' name='productarry[]' value='{$val}'{$checked}>{$val}</label><span style='margin-right: 25px;'></span>\n";
|
93
|
+
}
|
94
|
+
?>
|
95
|
+
<hr>
|
96
|
+
<form method="post">
|
97
|
+
id test:<select name="id">
|
98
|
+
<option value="1">1</option>
|
99
|
+
<option value="2">2</option>
|
100
|
+
<option value="3">3</option>
|
101
|
+
</select>
|
102
|
+
<input type="submit" value="go">
|
103
|
+
</form>
|
104
|
+
|
59
105
|
```
|
5
id
answer
CHANGED
File without changes
|
4
id
answer
CHANGED
@@ -31,6 +31,8 @@
|
|
31
31
|
SQLの調整と、ヒットしたものだけチェックする処理をいれました
|
32
32
|
```PHP
|
33
33
|
$rows=[];
|
34
|
+
$id=2;
|
35
|
+
|
34
36
|
$product = ['製品A','製品B','製品C','製品D','製品E'];
|
35
37
|
try{
|
36
38
|
$sql = "SELECT productarry FROM tbl where 1 ";
|
@@ -38,7 +40,7 @@
|
|
38
40
|
$sql.= "and productarry in('".implode("','",$product)."') ";
|
39
41
|
print $sql;//debug
|
40
42
|
$stm = $pdo->prepare($sql);
|
41
|
-
$stm->execute([
|
43
|
+
$stm->execute([$id]);
|
42
44
|
$rows = $stm->fetchAll(PDO::FETCH_ASSOC);
|
43
45
|
}catch(PDOException $e){
|
44
46
|
die($e->getMessage());
|
3
id
answer
CHANGED
@@ -34,10 +34,11 @@
|
|
34
34
|
$product = ['製品A','製品B','製品C','製品D','製品E'];
|
35
35
|
try{
|
36
36
|
$sql = "SELECT productarry FROM tbl where 1 ";
|
37
|
+
$sql = "and id=? ";
|
37
38
|
$sql.= "and productarry in('".implode("','",$product)."') ";
|
38
39
|
print $sql;//debug
|
39
40
|
$stm = $pdo->prepare($sql);
|
40
|
-
$stm->execute();
|
41
|
+
$stm->execute([2]);
|
41
42
|
$rows = $stm->fetchAll(PDO::FETCH_ASSOC);
|
42
43
|
}catch(PDOException $e){
|
43
44
|
die($e->getMessage());
|
2
調整
answer
CHANGED
@@ -35,6 +35,7 @@
|
|
35
35
|
try{
|
36
36
|
$sql = "SELECT productarry FROM tbl where 1 ";
|
37
37
|
$sql.= "and productarry in('".implode("','",$product)."') ";
|
38
|
+
print $sql;//debug
|
38
39
|
$stm = $pdo->prepare($sql);
|
39
40
|
$stm->execute();
|
40
41
|
$rows = $stm->fetchAll(PDO::FETCH_ASSOC);
|
1
調整
answer
CHANGED
@@ -25,4 +25,31 @@
|
|
25
25
|
echo "<label><input type='checkbox' name='productarry[]' value='{$val}'>{$val}</label><span style='margin-right: 25px;'></span>\n";
|
26
26
|
}
|
27
27
|
|
28
|
+
```
|
29
|
+
|
30
|
+
# 調整版
|
31
|
+
SQLの調整と、ヒットしたものだけチェックする処理をいれました
|
32
|
+
```PHP
|
33
|
+
$rows=[];
|
34
|
+
$product = ['製品A','製品B','製品C','製品D','製品E'];
|
35
|
+
try{
|
36
|
+
$sql = "SELECT productarry FROM tbl where 1 ";
|
37
|
+
$sql.= "and productarry in('".implode("','",$product)."') ";
|
38
|
+
$stm = $pdo->prepare($sql);
|
39
|
+
$stm->execute();
|
40
|
+
$rows = $stm->fetchAll(PDO::FETCH_ASSOC);
|
41
|
+
}catch(PDOException $e){
|
42
|
+
die($e->getMessage());
|
43
|
+
}
|
44
|
+
$data=array_map(function($x){return $x["productarry"];},$rows);
|
45
|
+
echo <<<eof
|
46
|
+
<div class='form-group'>
|
47
|
+
<div class='col-lg-8'>
|
48
|
+
<div class='checkbox' id='product'>
|
49
|
+
<h4>Product Type</h4>
|
50
|
+
eof;
|
51
|
+
foreach ($product as $val) {
|
52
|
+
$checked=(in_array($val,$data)!==false)?" checked":"";
|
53
|
+
echo "<label><input type='checkbox' name='productarry[]' value='{$val}'{$checked}>{$val}</label><span style='margin-right: 25px;'></span>\n";
|
54
|
+
}
|
28
55
|
```
|