検索フォームをgoogleで調べると、データベースに情報を貯めその情報を検索するときはmysqliに接続することが書かれたサイトが多く見つかります。(全部見ていないので100%とは言えません)しかし、apiの検索フォームについて書かれたサイトが見つかりません。
apiはデータベースを利用することはもとより禁じられており、またapi自体がデータベースなので検索フォームが設けられるはずです。
下記のコードは自分が考えたコードですが訂正するところがありましたら教えてください。お願いします。
※コードができましたので、表示しません。
検索フォームはでき、入力もできますが、カレーと入れても表示されません・
php
1<html> 2<head> 3<title>API_SAMPLE</title> 4</head> 5<body> 6<form action="" method="post" name="keyword"> 7 <p>検索したいキーワードを入力してください。</p> 8 <input type="search" name="search" placeholder="キーワードを入力"> 9 <input type="submit" name="search" value="検索"> 10</form> 11</body> 12</html> 13 14<?php 15if (isset ( $_POST ["search"] )) { 16$key='私のkey'; 17$count='50'; 18$large_area='〇〇'; 19$start ='2'; 20$genre=$_POST ["keyword"]; 21$format='xml'; 22$url='http://webservice.recruit.co.jp/hotpepper/gourmet/v1/?key='.$key.'&count='.$count.'&large_area='.$large_area.'&start='.$start.'&genre='.$keyword.'&format='.$format; 23$xml=simplexml_load_file($url); 24if(!$xml->shop){ 25 echo '見つかりませんでした'; 26 } else { 27 foreach($xml->shop as $r){ 28echo '<table>' ; 29 echo '<tr>'; 30 echo '<td>'; 31 echo $r->food->name; 32 echo '</td>'; 33 echo '<td>'; 34 echo $r->name; 35 echo '</td>'; 36 echo '</table>'; 37} 38} 39} 40 41 ?>
PHP
1<html> 2<head> 3<title>API_SAMPLE</title> 4</head> 5<body> 6<form action="" method="POST"> 7<input type="text" name="freeword"> 8<input type="submit"> 9</form> 10</body> 11</html> 12 13<?php 14if (isset ( $_POST ["search"] )) { 15$key='私のid'; 16$count='50'; 17$large_area='〇〇'; 18$start ='2'; 19$keyword=$_POST ["keyword"]; 20$format='xml'; 21$url='http://webservice.recruit.co.jp/hotpepper/gourmet/v1/?key='.$key.'&count='.$count.'&large_area='.$large_area.'&start='.$start.'&keyword='.$keyword.'&format='.$format;
回答3件
あなたの回答
tips
プレビュー