<?php
//-------------------------------------------------------------------//
// Rakuten Web Service SDK - /02/
//-------------------------------------------------------------------//
// ライブラリファイル等の読込

require_once dirname(__FILE__).'/../autoload.php';
require_once 
dirname(__FILE__).'/config.php';
require_once 
dirname(__FILE__).'/helper.php';

// プログラムの初期設定等

$client = new RakutenRws_Client();
$client->setApplicationId(RAKUTEN_APP_ID);
$client->setAffiliateId(RAKUTEN_APP_AFFILITE_ID);

// IchibaItemRankingの実行

// ランキングの配列変数
$my_ranking = array( 'genreId' => $_GET["searchid"]);

// IchibaItemRanking API でRankingを得る
$response $client->execute('IchibaItemRanking'$my_ranking );

// ヒアドキュメントでHTMLヘッダー部を出力

echo<<<EOD

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Rakuten Web Service SDK - /02/ </title>
<link rel="stylesheet" href="./style.css" type="text/css">
<link rel="stylesheet" href="./di-style.css" type="text/css">
</head>
<body>
<header>
<h1 align="center"><a href="./">Rakuten Web Service SDK - /02/</a></h1>
</header>
<div align="center">
<!-- Rakuten Web Services Attribution Snippet FROM HERE -->
<a href="http://webservice.rakuten.co.jp/" target="_blank"><img src="http://webservice.rakuten.co.jp/img/credit/200709/credit_31130.gif" border="0" alt="楽天ウェブサービスセンター" title="楽天ウェブサービスセンター" width="311" height="30"/></a>
<!-- Rakuten Web Services Attribution Snippet TO HERE -->
</div>

EOD;

// 検索結果の出力

if ($response->isOk()) { // レスポンスが正常かどうかを isOk() で確認する
    
echo '<h3 align="center">'$response['title'].'</h3>';
    echo 
'<p align="center"><a href="./">【戻る】</a></p>';
    
// foreach で商品情報を順次取得する。
    
echo '<div id="itemarea">';
        echo 
'<ul id="itemlist">';
    foreach (
$response as $item) {
        echo 
'<ul>';
        echo 
'<li class="item">';
        
// 商品価格「itemPrice」
        
$item_price $item['itemPrice'];
        
$formated_price number_format($item_price);
        echo 
'No【' $item['rank'] .'】価格:'$formated_price '円<br>';
        
// 商品名「itemName」
        
echo '<a href="' $item['affiliateUrl'] . '" class="itemname" target="_blank">' .  h(mb_strimwidth($item['itemName'], 060'...''UTF-8')) . '</a><br>';
                
//     商品画像「smallImageUrls」 アフィリエイトURL「affiliateUrl」
                
if (!empty($item['mediumImageUrls'][0]['imageUrl'])){
                        
$ImageURL=$item['mediumImageUrls'][0]['imageUrl'];
                        echo 
'<a href="' $item['affiliateUrl'] . '" class="itemname" target="_blank"><img src="' $ImageURL '"></img>' '</a><br>';
                }else{
                     echo 
'【No Image】';
                }
                echo 
'</li>';
        echo 
'</ul>';
    }
        echo 
'</ul>';
    echo 
'</div>';
} else {
    
// getMessage() でレスポンスメッセージを取得することができます
    
echo '<p align="center">Error:'.$response->getMessage().'</p>';
}

// ヒアドキュメントでHTMLフッター部を出力

echo<<<EOD

<div style="clear:both"></div>
<p align="center"><a href="./">【戻る】</a></p>
<div class="copyright" align="center">
        <p><small>&copy;2019 R10.Oh!Happy.JP</small></p>
</div>
</body>
</html>

EOD;

?>