yahooのAPIのコードをphpに書きました。ただ、僕が作成したphpには、whileloopがあり、それがwebサイトをパンクさせる原因になっているという指摘がありました。しかしwhile loopを除いた場合、店舗情報が思ったほど入手できないので困っています。
質問です。
while loopは必要ですか?また、while loopがなくても店舗情報はたくさん手に入りますか?
※下記にphpコードを記載します。
PHP
1<?php 2/* 3Template Name: takeout 4*/ 5?> 6 7<?php 8 9if(have_posts()): while(have_posts()): the_post();?> 10 11<h2><?php the_title(); ?></h2> 12 13<?php the_content(); ?> 14 15<?php endwhile; endif; ?> 16 17<!DOCTYPE html> 18<html lang="ja"> 19<head> 20<meta charset="UTF-8"> 21<title>YOLP</title> 22<head> 23<body> 24<?php 25 $id = '私のid'; 26 $area= 13; 27 $area =get_post_meta($post->ID, Area, true); 28 $city =urlencode($area); 29 30 31 $ct ='0114'; 32 $start = '1'; 33 $url = 'http://search.olp.yahooapis.jp/OpenLocalPlatform/V1/localSearch?appid='.$id.'&ac='.$area.'&gc='.$ct.'&results=100&start='.$start.'&detail=full'; 34 35 $xml = simplexml_load_file( $url ); 36 37 38 $total = $xml ->ResultInfo->Total; 39 40 $loop = (int)($total/100); 41 42 $i = 0; 43 while($i <= $loop){ 44 $start = 100*$i+1; 45 $url = 'http://search.olp.yahooapis.jp/OpenLocalPlatform/V1/localSearch?appid='.$id.'&ac='.$area.'&gc='.$ct.'&results=200&start='.$start.'&detail=full'; 46 $xml = simplexml_load_file( $url ); 47 48 foreach($xml->Feature as $item){ 49 50echo $item->Name. ',' . $item->Property->Yomi .',' . $item->Property->Tel1 . ',' . $item->Property->Address . ',' . $item->Property->Station->Railway . $item->Property->Station->Name . '駅' .$item->Property->Detail->OfficialPcUrl1; 51 echo '<br />'; 52 } 53 $i++; 54 } 55 56 ?> 57 58
あなたの回答
tips
プレビュー