質問編集履歴
1
失礼致しました。私なりにインデントを揃えました。見づらかったらすみません。
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
14
|
+
|
14
15
|
<?php
|
15
16
|
|
16
17
|
/**********************************************************************/
|
@@ -26,58 +27,53 @@
|
|
26
27
|
echo '<div style="margin:0; padding:0">';
|
27
28
|
|
28
29
|
?>
|
30
|
+
|
29
31
|
<div style="margin:0 0 2% 0;">
|
30
|
-
<form name="searchform" id="itemsearchform" method="get" action="">
|
32
|
+
<form name="searchform" id="itemsearchform" method="get" action="">
|
31
|
-
<input type="text" name="keyword" id="itemkeyword" value="" />
|
33
|
+
<input type="text" name="keyword" id="itemkeyword" value="" />
|
32
|
-
<input type="submit" id="itemsubmit" value="検索" />
|
34
|
+
<input type="submit" id="itemsubmit" value="検索" />
|
33
|
-
</form>
|
35
|
+
</form>
|
34
36
|
</div>
|
37
|
+
|
35
38
|
<?php
|
36
39
|
|
37
|
-
$keyword
|
40
|
+
$keyword = htmlspecialchars($_GET['keyword'], ENT_QUOTES);
|
38
|
-
$e_keyword
|
41
|
+
$e_keyword = urlencode($keyword);
|
39
42
|
$currentpage = (empty($_GET['page'])) ? 1 : $_GET['page'];
|
43
|
+
$first = $currentpage * 10 - 9;
|
44
|
+
$last = $currentpage * 10;
|
45
|
+
$shopcode = "********";//shopコード記載
|
46
|
+
$timestamp = strtotime('now');
|
47
|
+
$date = date('Y-n-j H:i:s',$timestamp);
|
48
|
+
$baseurl = 'https://app.rakuten.co.jp/services/api/IchibaItem/Search/20140222?format=json';
|
49
|
+
$rsparam = array();
|
40
50
|
|
41
|
-
$first = $currentpage * 10 - 9;
|
42
|
-
$last = $currentpage * 10;
|
43
|
-
$shopcode ="********";//shopコード記載
|
44
|
-
$timestamp =strtotime('now');
|
45
|
-
$date = date('Y-n-j H:i:s',$timestamp);
|
46
51
|
|
47
|
-
|
48
|
-
|
49
|
-
$baseurl = 'https://app.rakuten.co.jp/services/api/IchibaItem/Search/20140222?format=json';
|
50
|
-
$rsparam = array();
|
51
|
-
|
52
|
-
if ($e_keyword != "")
|
52
|
+
if ($e_keyword != ""){
|
53
|
-
|
53
|
+
$rsparam['keyword'] = $e_keyword;
|
54
54
|
}
|
55
55
|
|
56
56
|
$rsparam['applicationId'] = $appId;
|
57
|
-
$rsparam['hits']
|
57
|
+
$rsparam['hits'] = 30;
|
58
|
-
$rsparam['field']
|
58
|
+
$rsparam['field'] = 0;
|
59
|
-
$rsparam['imageFlag']
|
59
|
+
$rsparam['imageFlag'] = 0;
|
60
|
-
$rsparam['page']
|
60
|
+
$rsparam['page'] = $currentpage;
|
61
|
-
$rsparam['orFlag']
|
61
|
+
$rsparam['orFlag'] = 1;
|
62
|
-
$rsparam['first']
|
62
|
+
$rsparam['first'] = $first;
|
63
|
-
$rsparam['last']
|
63
|
+
$rsparam['last'] = $last;
|
64
|
-
$rsparam['shopCode']
|
64
|
+
$rsparam['shopCode'] = $shopcode;
|
65
65
|
|
66
|
-
|
67
|
-
|
68
66
|
foreach ($rsparam as $nr => $rsvalue) {
|
69
67
|
$palame .= '&'.$nr.'='.$rsvalue;
|
70
68
|
}
|
71
69
|
|
72
|
-
$rsurl
|
70
|
+
$rsurl = $baseurl.$palame;
|
73
|
-
|
74
|
-
$rs_json
|
71
|
+
$rs_json = @file_get_contents($rsurl, true);
|
75
|
-
|
76
|
-
$item
|
72
|
+
$item = json_decode($rs_json);
|
77
|
-
$Item
|
73
|
+
$Item = array();
|
78
|
-
$Items
|
74
|
+
$Items = $item->Items;
|
79
|
-
$count
|
75
|
+
$count = $item->count;
|
80
|
-
$hits
|
76
|
+
$hits = $rsparam['hits'];
|
81
77
|
$max_page = ceil($count/$hits);
|
82
78
|
|
83
79
|
// 商品数が1000を超える場合は1000に制限
|
@@ -101,84 +97,73 @@
|
|
101
97
|
$results_per_page = $hits;
|
102
98
|
}
|
103
99
|
|
104
|
-
|
100
|
+
$nextpage = $currentpage+1;
|
105
|
-
|
101
|
+
$prevpage = $currentpage-1;
|
106
102
|
|
103
|
+
|
107
104
|
for($i = 0; $i < $results_per_page; $i++) {
|
108
105
|
|
109
106
|
$imageFlag = $item->Items[$i]->Item->imageFlag;
|
110
107
|
|
111
108
|
if ($imageFlag == "1") {
|
112
|
-
$mediumImageUrls = $item->Items[$i]->Item->mediumImageUrls[0]->imageUrl;
|
113
109
|
|
110
|
+
$mediumImageUrls = $item->Items[$i]->Item->mediumImageUrls[0]->imageUrl;
|
114
|
-
$affiliateUrl[$i] = $item->Items[$i]->Item->affiliateUrl;
|
111
|
+
$affiliateUrl[$i] = $item->Items[$i]->Item->affiliateUrl;
|
112
|
+
$itemName[$i] = $item->Items[$i]->Item->itemName;
|
113
|
+
$itemCode[$i] = $item->Items[$i]->Item->itemCode;
|
114
|
+
$spCode[$i] = $item->Items[$i]->Item->shopCode;
|
115
|
+
$itemUrl[$i] = $item->Items[$i]->Item->itemUrl;
|
116
|
+
$postageFlag[$i] = number_format((int)$item->Items[$i]->Item->postageFlag);
|
117
|
+
$itemPrice[$i] = number_format((int)$item->Items[$i]->Item->itemPrice);
|
118
|
+
$itemCaption[$i] = mb_strimwidth($item->Items[$i]->Item->itemCaption, 0, 380, '...', 'UTF-8');
|
115
119
|
|
116
|
-
$itemName[$i] = $item->Items[$i]->Item->itemName;
|
117
120
|
|
118
|
-
$itemCode[$i] = $item->Items[$i]->Item->itemCode;
|
119
|
-
|
120
|
-
$spCode[$i] = $item->Items[$i]->Item->shopCode;
|
121
|
-
|
122
|
-
$itemUrl[$i] = $item->Items[$i]->Item->itemUrl;
|
123
|
-
|
124
|
-
$postageFlag[$i] = number_format((int)$item->Items[$i]->Item->postageFlag);
|
125
|
-
|
126
|
-
$itemPrice[$i] = number_format((int)$item->Items[$i]->Item->itemPrice);
|
127
|
-
|
128
|
-
$itemCaption[$i] = mb_strimwidth($item->Items[$i]->Item->itemCaption, 0, 380, '...', 'UTF-8');
|
129
|
-
|
130
121
|
echo '<div style="padding:10px 10px 0 10px;">';
|
131
|
-
|
132
122
|
echo '<div style="width:130px;height:130px;float:left;"><a href="'.$affiliateUrl[$i].'" target="_blank"><img src="'.$mediumImageUrls.'" alt="" /></a></div>';
|
133
|
-
|
134
123
|
echo '<div style="margin:0 0 0 136px;">'.$itemName[$i].'<br />';
|
135
|
-
|
136
124
|
echo '<span style="color:#ff0000;">価格 '.$itemPrice[$i].' 円</span><br />';
|
137
|
-
|
138
125
|
echo $itemUrl[$i].'<br />';
|
139
126
|
|
127
|
+
|
140
128
|
if($postageFlag[$i]==0){
|
141
|
-
|
129
|
+
echo "送料込".'<br />';
|
142
|
-
|
130
|
+
}else{
|
143
131
|
echo "送料別".'<br />';
|
144
132
|
}
|
145
|
-
|
146
|
-
|
147
133
|
|
148
134
|
echo $itemCode[$i].'</div>';
|
149
135
|
|
150
|
-
|
136
|
+
$mysql_con = mysql_connect ("*******","*******","*******");
|
151
|
-
if ($mysql_con == false) {
|
137
|
+
if ($mysql_con == false) {
|
152
|
-
|
138
|
+
print "DB_Connect Error!";
|
153
|
-
|
139
|
+
exit;
|
154
140
|
}
|
155
141
|
|
156
142
|
//MySQLのデータベースを選択
|
157
143
|
$select_db = mysql_select_db ("*******",$mysql_con);
|
158
|
-
if ($select_db == false) {
|
144
|
+
if ($select_db == false) {
|
159
|
-
|
145
|
+
print "DB_SELECT Error!";
|
160
|
-
|
146
|
+
exit;
|
161
147
|
}
|
162
148
|
|
163
|
-
|
149
|
+
//insert時の文字化け回避
|
150
|
+
mysql_query('set character set utf8');
|
164
151
|
|
165
|
-
// mysql_query('set character set utf8'); //insert時の文字化け回避
|
166
|
-
|
167
|
-
|
152
|
+
$sql = "INSERT INTO rakuten_api VALUES
|
168
|
-
|
153
|
+
('$spCode[$i]','$itemCode[$i]','$itemName[$i]','$itemPrice[$i]','$itemUrl[$i]','$date')";
|
169
154
|
|
155
|
+
$result = mysql_query ($sql,$mysql_con);
|
170
156
|
|
171
|
-
//$result = mysql_query ($sql,$mysql_con);
|
172
|
-
|
173
157
|
//実行した結果にエラーあったらエラー表示する
|
174
|
-
|
158
|
+
if ($result == false) {
|
175
|
-
|
159
|
+
print "Data Insert Error!";
|
176
|
-
|
160
|
+
exit;
|
177
|
-
|
161
|
+
} else {
|
178
|
-
|
162
|
+
print "Data Insert OK!";
|
179
|
-
|
163
|
+
}
|
180
164
|
|
181
165
|
?>
|
166
|
+
|
182
167
|
<div style="clear:both; visibility:hidden; height:10px;">クリア</div>
|
183
168
|
<hr style="width:100%;border-top:1px dotted #bbb;" />
|
184
169
|
</div>
|
@@ -188,14 +173,15 @@
|
|
188
173
|
if(isset($item)){
|
189
174
|
?>
|
190
175
|
|
176
|
+
<!-- Rakuten Web Services Attribution Snippet FROM HERE -->
|
177
|
+
<div>
|
178
|
+
<a href="http://webservice.rakuten.co.jp/" target="_blank">
|
179
|
+
<img src="http://webservice.rakuten.co.jp/img/credit/200709/credit_31130.gif" border="0" alt="楽天ウェブサービスセンター" title="楽天ウェブサービスセンター" width="311" height="30"/>
|
180
|
+
</a>
|
181
|
+
</div>
|
182
|
+
<!-- Rakuten Web Services Attribution Snippet TO HERE -->
|
183
|
+
<div>全 <?php echo number_format($count); ?> 品数</div><?php }
|
191
184
|
|
192
|
-
|
193
|
-
|
194
|
-
<div><!-- Rakuten Web Services Attribution Snippet FROM HERE -->
|
195
|
-
<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>
|
196
|
-
<div>全 <?php echo number_format($count); ?> 品数</div>
|
197
|
-
<?php }
|
198
|
-
|
199
185
|
// ページャー
|
200
186
|
echo '<p>';
|
201
187
|
|
@@ -210,49 +196,47 @@
|
|
210
196
|
echo $html_Page_Link;
|
211
197
|
|
212
198
|
function Page_Link($max_page,$currentpage,$nextpage,$url_a,$url_b){
|
213
|
-
|
214
|
-
$html = "";
|
215
199
|
|
216
|
-
|
200
|
+
$html = "";
|
217
201
|
|
218
|
-
|
202
|
+
if($max_page < 1) return $html;
|
219
203
|
|
220
|
-
|
204
|
+
if($currentpage > 1) $html .= $url_a.($currentpage-1).$url_b.' style="background-color: #ffffff; margin: 0; padding: 0.2em 0.5em; border: solid 1px; text-decoration: none;"'.">«</a>";
|
221
205
|
|
222
|
-
|
206
|
+
$prevpage = $currentpage - $nextpage;
|
223
207
|
|
224
|
-
|
208
|
+
while ($prevpage < $currentpage) {
|
225
209
|
|
226
|
-
|
210
|
+
$prevpage++;
|
227
211
|
|
228
|
-
|
212
|
+
if($prevpage > 1) $html .= $url_a.($prevpage-1).$url_b.">".($prevpage-1)."</a>";
|
229
213
|
|
230
|
-
|
214
|
+
}
|
231
215
|
|
232
|
-
|
216
|
+
$html .= '<span style="background-color: #ff0000; color: #ffffff; margin: 0; padding: 0.2em 0.5em; border: solid 1px #ff0000; text-decoration: none;">'.$currentpage.'</span>';
|
233
217
|
|
234
|
-
|
218
|
+
if($currentpage < $max_page){
|
235
219
|
|
236
|
-
|
220
|
+
$max_page = $max_page - $currentpage;
|
237
221
|
|
238
|
-
|
222
|
+
if($max_page > $nextpage) $max_page=$nextpage;
|
239
223
|
|
240
|
-
|
224
|
+
$plus=0;
|
241
225
|
|
226
|
+
while ($plus < $max_page) {
|
242
|
-
|
227
|
+
$nextpage=$currentpage+$plus+1;
|
243
228
|
|
244
|
-
|
229
|
+
$html .= $url_a.$nextpage.$url_b.">".$nextpage."</a>";
|
245
230
|
|
246
|
-
|
231
|
+
$plus++;
|
232
|
+
}
|
247
233
|
|
248
|
-
|
234
|
+
$html .= $url_a.($currentpage+1).$url_b.' style="background-color: #ffffff; color: #ff0000; margin: 0; padding: 0.2em 0.4em; border: solid 1px; text-decoration: none;"'.">»</a>";
|
249
235
|
|
250
|
-
|
236
|
+
}
|
251
237
|
|
252
|
-
|
238
|
+
return $html;
|
253
239
|
|
254
|
-
return $html;
|
255
|
-
|
256
240
|
}
|
257
241
|
|
258
242
|
echo '</p>';
|