質問編集履歴

5

修正

2019/03/22 04:21

投稿

ariiiiiga
ariiiiiga

スコア66

test CHANGED
File without changes
test CHANGED
@@ -110,61 +110,71 @@
110
110
 
111
111
 
112
112
 
113
- // 件数取得
114
-
115
- $sql = $pdo->prepare('select COUNT(*) AS "TOTAL" from hosts '.$whereSql);
116
-
117
-
118
-
119
113
  // 表示用
120
114
 
121
- $sql = $pdo->prepare('select * from hosts '.$whereSql.' order by post_id desc limit :limit offset :offset');
122
-
123
-
124
-
125
- $sql->bindValue(":offset", $offset, PDO::PARAM_INT);
126
-
127
- $sql->bindValue(":limit", PAGE_LIMIT, PDO::PARAM_INT);
128
-
129
- if ( $name ) {
130
-
131
- $sql->bindValue(":name", "%" . addcslashes($name, '\_%') . "%", PDO::PARAM_STR);
132
-
133
- }
134
-
135
- if ( $shop ) {
136
-
137
- $sql->bindValue(":shop", "%" . addcslashes($shop, '\_%') . "%", PDO::PARAM_STR);
138
-
139
- }
140
-
141
- if ( $user_id ) {
142
-
143
- $sql->bindValue(":user_id", addcslashes($user_id, '\_%') , PDO::PARAM_STR);
144
-
145
- }
146
-
147
- $sql->execute();
148
-
149
-
150
-
151
- // 検索結果取得
152
-
153
- $result = $sql->fetchAll();
154
-
155
- // Total件数
156
-
157
-
158
-
159
- $all = array();
160
-
161
- if ( $result ) {
162
-
163
- $all['TOTAL'] = $result[0]['TOTAL'];
164
-
165
- }
166
-
167
-
115
+ $sql = $pdo->prepare('select * from hosts '.$whereSql.' order by post_id desc limit :limit offset :offset');
116
+
117
+
118
+
119
+ $sql->bindValue(":offset", $offset, PDO::PARAM_INT);
120
+
121
+ $sql->bindValue(":limit", PAGE_LIMIT, PDO::PARAM_INT);
122
+
123
+ if ( $name ) {
124
+
125
+ $sql->bindValue(":name", "%" . addcslashes($name, '\_%') . "%", PDO::PARAM_STR);
126
+
127
+ }
128
+
129
+ if ( $shop ) {
130
+
131
+ $sql->bindValue(":shop", "%" . addcslashes($shop, '\_%') . "%", PDO::PARAM_STR);
132
+
133
+ }
134
+
135
+ if ( $user_id ) {
136
+
137
+ $sql->bindValue(":user_id", addcslashes($user_id, '\_%') , PDO::PARAM_STR);
138
+
139
+ }
140
+
141
+ $sql->execute();
142
+
143
+
144
+
145
+ // 検索結果取得
146
+
147
+ $result = $sql->fetchAll();
148
+
149
+
150
+
151
+ // 件数取得
152
+
153
+ $totalRow = $pdo->query('select COUNT(*) AS "TOTAL" from hosts '.$whereSql);
154
+
155
+ if ( $name ) {
156
+
157
+ $totalRow->bindValue(":name", "%" . addcslashes($name, '\_%') . "%", PDO::PARAM_STR);
158
+
159
+ }
160
+
161
+ if ( $shop ) {
162
+
163
+ $totalRow->bindValue(":shop", "%" . addcslashes($shop, '\_%') . "%", PDO::PARAM_STR);
164
+
165
+ }
166
+
167
+ if ( $user_id ) {
168
+
169
+ $totalRow->bindValue(":user_id", addcslashes($user_id, '\_%') , PDO::PARAM_STR);
170
+
171
+ }
172
+
173
+
174
+
175
+ $totalRow->execute();
176
+
177
+ $all = $totalRow->fetch(PDO::FETCH_ASSOC);
168
178
 
169
179
  ?>
170
180
 

4

修正

2019/03/22 04:21

投稿

ariiiiiga
ariiiiiga

スコア66

test CHANGED
File without changes
test CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
 
42
42
 
43
- $pdo = new PDO ( "pgsql:host=myhost;port=5432;dbname=mydb;user=myuser;password=*****" );
43
+ $pdo = new PDO ( "pgsql:host=myhost;port=5432;dbname=mydb;user=myuser;password=*****" );
44
44
 
45
45
  //カラム名を小文字にする
46
46
 

3

変更

2019/03/20 06:42

投稿

ariiiiiga
ariiiiiga

スコア66

test CHANGED
File without changes
test CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
 
42
42
 
43
- $pdo = new PDO ( "pgsql:host=ec2-50-19-109-120.compute-1.amazonaws.com;port=5432;dbname=d59sri1j1hlv0b;user=myeojtgygingbl;password=a3a14973f16546823bd88fb405ae36b0143db905ba9598c07acc9eeb47c1e4cb" );
43
+ $pdo = new PDO ( "pgsql:host=myhost;port=5432;dbname=mydb;user=myuser;password=*****" );
44
44
 
45
45
  //カラム名を小文字にする
46
46
 

2

PHP,SQ文の変更

2019/03/20 06:40

投稿

ariiiiiga
ariiiiiga

スコア66

test CHANGED
File without changes
test CHANGED
@@ -30,26 +30,24 @@
30
30
 
31
31
  <?php
32
32
 
33
-
34
-
35
- ini_set( 'display_errors', 1 );
36
-
37
- ini_set( 'error_reporting', E_ALL );
38
-
39
- // 取得件数
40
-
41
- define('PAGE_LIMIT', 10);
42
-
43
-
44
-
45
-
46
-
47
- $pdo = new PDO ( "pgsql:host=localhost;port=5432;dbname=,mydb;user=name;password=*****" );
48
-
49
-
33
+ ini_set( 'display_errors', 1 );
34
+
35
+ ini_set( 'error_reporting', E_ALL );
36
+
37
+ // 取得件数
38
+
39
+ define('PAGE_LIMIT', 10);
40
+
41
+
42
+
43
+ $pdo = new PDO ( "pgsql:host=ec2-50-19-109-120.compute-1.amazonaws.com;port=5432;dbname=d59sri1j1hlv0b;user=myeojtgygingbl;password=a3a14973f16546823bd88fb405ae36b0143db905ba9598c07acc9eeb47c1e4cb" );
44
+
45
+ //カラム名を小文字にする
50
46
 
51
47
  $pdo ->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
52
48
 
49
+ // SQL実行に失敗した場合、例外を発生させる
50
+
53
51
  $pdo->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
54
52
 
55
53
  $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
@@ -110,17 +108,17 @@
110
108
 
111
109
  }
112
110
 
113
-          
114
-
111
+
112
+
115
-      // 件数取得
113
+ // 件数取得
116
-
114
+
117
- $sql = $pdo->prepare('select COUNT(*) AS "TOTAL" from hosts '.$whereSql);
115
+ $sql = $pdo->prepare('select COUNT(*) AS "TOTAL" from hosts '.$whereSql);
118
-
119
-
120
-
116
+
117
+
118
+
121
- // 表示用
119
+ // 表示用
122
-
120
+
123
- $sql = $pdo->prepare('select * from hosts '.$whereSql.' order by post_id desc limit :limit offset :offset');
121
+ $sql = $pdo->prepare('select * from hosts '.$whereSql.' order by post_id desc limit :limit offset :offset');
124
122
 
125
123
 
126
124
 
@@ -142,7 +140,7 @@
142
140
 
143
141
  if ( $user_id ) {
144
142
 
145
- $sql->bindValue(":user_id", addcslashes($user_id, '\_%') , PDO::PARAM_STR);
143
+ $sql->bindValue(":user_id", addcslashes($user_id, '\_%') , PDO::PARAM_STR);
146
144
 
147
145
  }
148
146
 
@@ -154,15 +152,17 @@
154
152
 
155
153
  $result = $sql->fetchAll();
156
154
 
157
-
155
+ // Total件数
158
-
156
+
157
+
158
+
159
- $all = array();
159
+ $all = array();
160
-
160
+
161
- if ( $result ) {
161
+ if ( $result ) {
162
-
162
+
163
- $all['TOTAL'] = $result[0]['TOTAL'];
163
+ $all['TOTAL'] = $result[0]['TOTAL'];
164
-
164
+
165
- }
165
+ }
166
166
 
167
167
 
168
168
 
@@ -180,12 +180,62 @@
180
180
 
181
181
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
182
182
 
183
+ <link rel="stylesheet" as="style" href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css" media="all" onload="this.rel='stylesheet'">
184
+
185
+ <link rel="stylesheet" as="style" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" media="all" onload="this.rel='stylesheet'">
186
+
183
187
  </head>
184
188
 
185
189
  <body>
186
190
 
187
191
 
188
192
 
193
+ <div class="make">
194
+
195
+ <style type="text/css">
196
+
197
+ .make{
198
+
199
+ text-align: center;
200
+
201
+ font-size:15px;
202
+
203
+ font-weight:bold;
204
+
205
+ font-size:20px;
206
+
207
+ }
208
+
209
+ input{
210
+
211
+ padding:10px 10px ;
212
+
213
+ border-radius:30px;
214
+
215
+ margin:10px 0;
216
+
217
+ }
218
+
219
+ </style>
220
+
221
+ <input type="button" onclick="location.href='user_register.php'"value="MyIDを発行・確認">
222
+
223
+ <input type="button" onclick="location.href='post_new_review.php'"value="NEWLOGを書く">
224
+
225
+ </div>
226
+
227
+
228
+
229
+ <style type="text/css">
230
+
231
+ h3 {
232
+
233
+ text-align: center;
234
+
235
+ }
236
+
237
+ </style>
238
+
189
239
  <h3>検索フォーム</h3>
190
240
 
191
241
  <div class="col-xs-12 well">
@@ -194,7 +244,7 @@
194
244
 
195
245
  <div class="form-group ">
196
246
 
197
- <label for="InputName">名</label>
247
+ <label for="InputName">ホスト名</label>
198
248
 
199
249
  <input name="name" class="form-control" id="InputName" value="<?= $name ?>">
200
250
 
@@ -234,11 +284,11 @@
234
284
 
235
285
  <th>名前</th>
236
286
 
237
-  <th>店舗名</th>
287
+ <th>店舗名</th>
238
-
288
+
239
-  <th>評価</th>
289
+ <th>評価</th>
240
-
290
+
241
-    <th>コメント</th>
291
+ <th>コメント</th>
242
292
 
243
293
  </tr>
244
294
 
@@ -278,7 +328,29 @@
278
328
 
279
329
  </table>
280
330
 
281
-
331
+ <!-- ページネーション -->
332
+
333
+ <?php if ( $p > 0 ) : ?>
334
+
335
+ <a href="index.php?search=1&name=<?= $name ?>&shop=<?= $shop ?>&user_id=<?= $user_id ?>&p=<?= $p-1 ?>" class="pull-left">戻る</a>
336
+
337
+ <?php else : ?>
338
+
339
+ <span class="pull-left">最新</span>
340
+
341
+ <?php endif; ?>
342
+
343
+
344
+
345
+ <?php if ( $all['TOTAL'] - (PAGE_LIMIT * $p ) > PAGE_LIMIT ) : ?>
346
+
347
+ <a href="index.php?search=1&name=<?= $name ?>&shop=<?= $shop ?>&user_id=<?= $user_id ?>&p=<?= $p+1 ?>" class="pull-right">次へ</a>
348
+
349
+ <?php else : ?>
350
+
351
+ <span class="pull-right">末尾</span>
352
+
353
+ <?php endif; ?>
282
354
 
283
355
 
284
356
 
@@ -300,6 +372,8 @@
300
372
 
301
373
 
302
374
 
375
+
376
+
303
377
  ```
304
378
 
305
379
 

1

PHP,SQL部分の変更

2019/03/20 06:38

投稿

ariiiiiga
ariiiiiga

スコア66

test CHANGED
File without changes
test CHANGED
@@ -32,13 +32,13 @@
32
32
 
33
33
 
34
34
 
35
- ini_set( 'display_errors', 1 );
35
+ ini_set( 'display_errors', 1 );
36
-
36
+
37
- ini_set( 'error_reporting', E_ALL );
37
+ ini_set( 'error_reporting', E_ALL );
38
-
38
+
39
- // 取得件数
39
+ // 取得件数
40
-
40
+
41
- define('PAGE_LIMIT', 10);
41
+ define('PAGE_LIMIT', 10);
42
42
 
43
43
 
44
44
 
@@ -86,7 +86,7 @@
86
86
 
87
87
  if ( $name ) {
88
88
 
89
- $where[] = "name like :name";
89
+ $where[] = "name like :name";
90
90
 
91
91
  }
92
92
 
@@ -112,9 +112,15 @@
112
112
 
113
113
           
114
114
 
115
+      // 件数取得
116
+
117
+ $sql = $pdo->prepare('select COUNT(*) AS "TOTAL" from hosts '.$whereSql);
118
+
119
+
120
+
115
-      //Postgresに変更した
121
+ // 表示
116
-
122
+
117
- $sql = $pdo->prepare('select *, COUNT(*) OVER() AS "TOTAL" from hosts '.$whereSql.' order by post_id desc limit :limit offset :offset');
123
+ $sql = $pdo->prepare('select * from hosts '.$whereSql.' order by post_id desc limit :limit offset :offset');
118
124
 
119
125
 
120
126
 
@@ -144,13 +150,19 @@
144
150
 
145
151
 
146
152
 
147
- //Postgres用に変更した
153
+ // 検索結果取得
148
154
 
149
155
  $result = $sql->fetchAll();
150
156
 
157
+
158
+
159
+ $all = array();
160
+
151
- //Postgres用に変更した
161
+ if ( $result ) {
152
-
162
+
153
- $all = $sql->fetch(PDO::FETCH_ASSOC);
163
+ $all['TOTAL'] = $result[0]['TOTAL'];
164
+
165
+ }
154
166
 
155
167
 
156
168