回答編集履歴
2
追加
test
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
method=GET版
|
2
|
+
|
1
3
|
```PHP
|
2
4
|
|
3
5
|
|
@@ -193,3 +195,227 @@
|
|
193
195
|
$key = '';
|
194
196
|
|
195
197
|
の部分だけを自分のにすれば動くPOSTかGETかわかんないからGETにした
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
追記 2016/08/17 12:11
|
202
|
+
|
203
|
+
method=POST版
|
204
|
+
|
205
|
+
```
|
206
|
+
|
207
|
+
PHP
|
208
|
+
|
209
|
+
<?php
|
210
|
+
|
211
|
+
session_start();
|
212
|
+
|
213
|
+
?>
|
214
|
+
|
215
|
+
<html>
|
216
|
+
|
217
|
+
<head>
|
218
|
+
|
219
|
+
<title>API_SAMPLE2</title>
|
220
|
+
|
221
|
+
<style>
|
222
|
+
|
223
|
+
.current {
|
224
|
+
|
225
|
+
font-weight: bold;
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
</style>
|
230
|
+
|
231
|
+
</head>
|
232
|
+
|
233
|
+
<body>
|
234
|
+
|
235
|
+
<form method="POST">
|
236
|
+
|
237
|
+
<input type="text" name="keyword">
|
238
|
+
|
239
|
+
<select name="budget">
|
240
|
+
|
241
|
+
<option value="B001">〜2000円</option>
|
242
|
+
|
243
|
+
<option value="B002">2001円〜3000円</option>
|
244
|
+
|
245
|
+
<option value="B003">3001円〜4000円</option>
|
246
|
+
|
247
|
+
</select>
|
248
|
+
|
249
|
+
<input type="submit" name="search" value="検索" onFocus="this.select()">
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
<?php
|
256
|
+
|
257
|
+
if(isset($_GET["page"]) || isset($_POST["search"])){
|
258
|
+
|
259
|
+
if(isset($_POST["search"])){
|
260
|
+
|
261
|
+
unset($_SESSION["budget"]);
|
262
|
+
|
263
|
+
unset($_SESSION["keyword"]);
|
264
|
+
|
265
|
+
$_SESSION["budget"] =$_POST["budget"];
|
266
|
+
|
267
|
+
$_SESSION["keyword"] =$_POST["keyword"];
|
268
|
+
|
269
|
+
$page=1;
|
270
|
+
|
271
|
+
}else{
|
272
|
+
|
273
|
+
$page=$_GET ["page"];
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
$key = '33e69b320cee12b3';
|
278
|
+
|
279
|
+
$count = '50';
|
280
|
+
|
281
|
+
$start = 1 + ($page - 1) * 10;
|
282
|
+
|
283
|
+
$budget = $_SESSION["budget"];
|
284
|
+
|
285
|
+
$keyword = $_SESSION["keyword"];
|
286
|
+
|
287
|
+
$format = 'xml';
|
288
|
+
|
289
|
+
$url = 'http://webservice.recruit.co.jp/hotpepper/gourmet/v1/?key=' . $key . '&count=' . $count . '&start=' . $start . '&keyword=' . $keyword . '&budget=' . $budget . '&format=' . $format;
|
290
|
+
|
291
|
+
$xml = simplexml_load_file ( $url );
|
292
|
+
|
293
|
+
$total_count = $xml->results_available;
|
294
|
+
|
295
|
+
$limit = ceil ( $total_count / $count ); // 最大ページ数
|
296
|
+
|
297
|
+
function paging($limit, $page, $disp = 5) {
|
298
|
+
|
299
|
+
global $budget;
|
300
|
+
|
301
|
+
global $keyword;
|
302
|
+
|
303
|
+
// $dispはページ番号の表示数
|
304
|
+
|
305
|
+
$next = $page + 1;
|
306
|
+
|
307
|
+
$prev = $page - 1;
|
308
|
+
|
309
|
+
// ページ番号リンク用
|
310
|
+
|
311
|
+
$start = ($page - floor ( $disp / 2 ) > 0) ? ($page - floor ( $disp / 2 )) : 1; // 始点
|
312
|
+
|
313
|
+
// print $start;
|
314
|
+
|
315
|
+
$end = ($start > 1) ? ($page + floor ( $disp / 2 )) : $disp; // 終点
|
316
|
+
|
317
|
+
$start = ($limit < $end) ? $start - ($end - $limit) : $start; // 始点再計算
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
if ($page != 1) {
|
322
|
+
|
323
|
+
print '<a name="paging" href="?page=' . $prev .'">« 前へ</a>';
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
// 最初のページへのリンク
|
328
|
+
|
329
|
+
if ($start >= floor ( $disp / 2 )) {
|
330
|
+
|
331
|
+
print '<a name="paging" href="?page=1">1</a>';
|
332
|
+
|
333
|
+
if ($start > floor ( $disp / 2 ))
|
334
|
+
|
335
|
+
print "..."; // ドットの表示
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
for($i = $start; $i <= $end; $i ++) { // ページリンク表示ループ
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
$class = ($page == $i) ? ' class="current"' : ""; // 現在地を表すCSSクラス
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
if ($i <= $limit && $i > 0) // 1以上最大ページ数以下の場合
|
348
|
+
|
349
|
+
print '<a name="paging" href="?page=' . $i . '"' . $class . '>' . $i . '</a>'; // ページ番号リンク表示
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
// 最後のページへのリンク
|
354
|
+
|
355
|
+
if ($limit > $end) {
|
356
|
+
|
357
|
+
if ($limit - 1 > $end)
|
358
|
+
|
359
|
+
print "..."; // ドットの表示
|
360
|
+
|
361
|
+
print '<a name="paging" href="?page=' . $limit . '">' . $limit . '</a>';
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
if ($page < $limit) {
|
366
|
+
|
367
|
+
print '<a name="paging" href="?page=' . $next . '">次へ »</a>';
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
}
|
372
|
+
|
373
|
+
paging ( $limit, $page );
|
374
|
+
|
375
|
+
?>
|
376
|
+
|
377
|
+
<table border=1>
|
378
|
+
|
379
|
+
<tr>
|
380
|
+
|
381
|
+
<td></td>
|
382
|
+
|
383
|
+
<td>店名</td>
|
384
|
+
|
385
|
+
<td>住所</td>
|
386
|
+
|
387
|
+
</tr>
|
388
|
+
|
389
|
+
<?php
|
390
|
+
|
391
|
+
$l = 1;
|
392
|
+
|
393
|
+
foreach ( $xml->shop as $r ) {?>
|
394
|
+
|
395
|
+
<tr>
|
396
|
+
|
397
|
+
<td><?php echo $l+($page-1)*$count;?></td>
|
398
|
+
|
399
|
+
<td><?php echo $r->name;?></td>
|
400
|
+
|
401
|
+
<td><?php echo $r->address;?></td>
|
402
|
+
|
403
|
+
</tr>
|
404
|
+
|
405
|
+
<?php $l++;?>
|
406
|
+
|
407
|
+
<?}?>
|
408
|
+
|
409
|
+
</table>
|
410
|
+
|
411
|
+
<?php }?>
|
412
|
+
|
413
|
+
</form>
|
414
|
+
|
415
|
+
</body>
|
416
|
+
|
417
|
+
</html>
|
418
|
+
|
419
|
+
```
|
420
|
+
|
421
|
+
今度もコピペで動くようになっている
|
1
修正
test
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
$page = empty ( $_GET ["page"] ) ? 1 : $_GET ["page"]; // ページ番号
|
46
46
|
|
47
|
-
$key = '';
|
47
|
+
$key = '33e69b320cee12b3';
|
48
48
|
|
49
49
|
$count = '50';
|
50
50
|
|
@@ -98,7 +98,7 @@
|
|
98
98
|
|
99
99
|
if ($start >= floor ( $disp / 2 )) {
|
100
100
|
|
101
|
-
print '<a name="paging" href="?page=1&budget=' . $budget . '">1</a>';
|
101
|
+
print '<a name="paging" href="?page=1&budget=' . $budget . '&keyword=' . $keyword . '">1</a>';
|
102
102
|
|
103
103
|
if ($start > floor ( $disp / 2 ))
|
104
104
|
|