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

質問編集履歴

2

コードの詳細追記

2019/10/04 05:44

投稿

narugaro
narugaro

スコア5

title CHANGED
File without changes
body CHANGED
@@ -7,10 +7,16 @@
7
7
 
8
8
  ```
9
9
  post_id meta_key meta_value
10
+ 1 イベント名 役員会議
11
+ 1 名前 山田太郎
10
12
  1 件名1 参加
11
13
  1 件名2 不参加
14
+ 2 イベント名 役員会議
15
+ 2 名前 田中花子
12
16
  2 件名1 参加
13
17
  2 件名2 参加
18
+ 3 イベント名 合同イベント
19
+ 3 名前 鈴木一郎
14
20
  3 件名1 不参加
15
21
  3 件名2 不参加
16
22
 
@@ -19,22 +25,31 @@
19
25
  ### 現在のソースコード
20
26
 
21
27
  ```php
28
+ $title = '役員会議';
29
+ $event_name = "イベント名";
30
+ $sql = "SELECT *
31
+ FROM at_postmeta
32
+ WHERE meta_key = '$event_name'
33
+ AND meta_value = '$title'";
34
+ $result1 = mysql_query($sql);
35
+
22
36
  while ($row = mysql_fetch_assoc($result1)) {
23
- $post_id = $row['post_id'];
37
+ $post_id = $row['post_id'];
24
- $label1 = "件名1";
38
+ $label1 = "件名1";
25
- $sanka = "参加";
39
+ $sanka = "参加";
26
40
 
27
- $sql = "SELECT COUNT(meta_value = '$sanka' OR null) AS cnt
41
+ $sql = "SELECT COUNT(meta_value = '$sanka' OR null) AS cnt
28
- FROM at_postmeta
42
+ FROM at_postmeta
29
- WHERE post_id = '$post_id'
43
+ WHERE post_id = '$post_id'
30
- AND meta_key = '$label1'
44
+ AND meta_key = '$label1'
31
- ";
45
+ ";
32
- $result = mysql_query($sql);
46
+ $result = mysql_query($sql);
33
47
 
34
- while ($row = mysql_fetch_assoc($result)){
48
+ while ($row = mysql_fetch_assoc($result)){
35
- $sum += $row['cnt'];
49
+ $sum += $row['cnt'];
50
+ }
51
+ echo $sum;
36
52
  }
37
- echo $sum;
38
53
  ```
39
54
 
40
55
  ### 出力結果

1

誤字修正

2019/10/04 05:43

投稿

narugaro
narugaro

スコア5

title CHANGED
File without changes
body CHANGED
@@ -19,6 +19,7 @@
19
19
  ### 現在のソースコード
20
20
 
21
21
  ```php
22
+ while ($row = mysql_fetch_assoc($result1)) {
22
23
  $post_id = $row['post_id'];
23
24
  $label1 = "件名1";
24
25
  $sanka = "参加";