eBay 中的 IF 语句 API
IF Statement in eBay API
我有一个 PHP 代码可以使用 eBay API 通过关键字获得 5 个结果。
我想添加 IF 条件以仅在有结果时显示标题<h2>List of products</h2>
。
// Check to see if the request was successful, else print an error
if ($resp->ack == "Success") {
$results = '';
// If the response was loaded, parse it and build links
foreach($resp->searchResult->item as $item) {
$pic = $item->galleryPlusPictureURL;
$link = $item->viewItemURL;
$title = $item->title;
$price = $item->sellingStatus->currentPrice;
// For each SearchResultItem node, build a link and append it to $results
$results .= "<tr><td style=\"text-align: center;\"><img width=\"300\" src=\"$pic\"></td></tr><tr><td><a href=\"$link\" rel=\"nofollow\">$title</a></td></tr><tr><td style=\"text-align: right;\">".$price." € <div><a href=\"$link\" rel=\"nofollow\"><p class=\"bux\">> Offer</p></a></div></td></tr>";
}
}
// If the response does not indicate 'Success,' print an error
else {
$results = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
$results .= "AppID for the Production environment.</h3>";
}
echo "<table>".$results."</table>";
如何编辑上面的代码,以便仅在至少有一个结果时才显示 <h2>List of products</h2>
,否则什么都不显示?
// Check to see if the request was successful, else print an error
if ($resp->ack == "Success") {
$results = '';
// If the response was loaded, parse it and build links
foreach($resp->searchResult->item as $item) {
$pic = $item->galleryPlusPictureURL;
$link = $item->viewItemURL;
$title = $item->title;
$price = $item->sellingStatus->currentPrice;
// For each SearchResultItem node, build a link and append it to $results
$results .= "<tr><td style=\"text-align: center;\"><img width=\"300\" src=\"$pic\"></td></tr><tr><td><a href=\"$link\" rel=\"nofollow\">$title</a></td></tr><tr><td style=\"text-align: right;\">".$price." € <div><a href=\"$link\" rel=\"nofollow\"><p class=\"bux\">> Offer</p></a></div></td></tr>";
}
if ( ! empty($results) )
$results = '<h2>List of products</h2>'. $results;
}
// If the response does not indicate 'Success,' print an error
else {
$results = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
$results .= "AppID for the Production environment.</h3>";
}
echo "<table>".$results."</table>";
我有一个 PHP 代码可以使用 eBay API 通过关键字获得 5 个结果。
我想添加 IF 条件以仅在有结果时显示标题<h2>List of products</h2>
。
// Check to see if the request was successful, else print an error
if ($resp->ack == "Success") {
$results = '';
// If the response was loaded, parse it and build links
foreach($resp->searchResult->item as $item) {
$pic = $item->galleryPlusPictureURL;
$link = $item->viewItemURL;
$title = $item->title;
$price = $item->sellingStatus->currentPrice;
// For each SearchResultItem node, build a link and append it to $results
$results .= "<tr><td style=\"text-align: center;\"><img width=\"300\" src=\"$pic\"></td></tr><tr><td><a href=\"$link\" rel=\"nofollow\">$title</a></td></tr><tr><td style=\"text-align: right;\">".$price." € <div><a href=\"$link\" rel=\"nofollow\"><p class=\"bux\">> Offer</p></a></div></td></tr>";
}
}
// If the response does not indicate 'Success,' print an error
else {
$results = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
$results .= "AppID for the Production environment.</h3>";
}
echo "<table>".$results."</table>";
如何编辑上面的代码,以便仅在至少有一个结果时才显示 <h2>List of products</h2>
,否则什么都不显示?
// Check to see if the request was successful, else print an error
if ($resp->ack == "Success") {
$results = '';
// If the response was loaded, parse it and build links
foreach($resp->searchResult->item as $item) {
$pic = $item->galleryPlusPictureURL;
$link = $item->viewItemURL;
$title = $item->title;
$price = $item->sellingStatus->currentPrice;
// For each SearchResultItem node, build a link and append it to $results
$results .= "<tr><td style=\"text-align: center;\"><img width=\"300\" src=\"$pic\"></td></tr><tr><td><a href=\"$link\" rel=\"nofollow\">$title</a></td></tr><tr><td style=\"text-align: right;\">".$price." € <div><a href=\"$link\" rel=\"nofollow\"><p class=\"bux\">> Offer</p></a></div></td></tr>";
}
if ( ! empty($results) )
$results = '<h2>List of products</h2>'. $results;
}
// If the response does not indicate 'Success,' print an error
else {
$results = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
$results .= "AppID for the Production environment.</h3>";
}
echo "<table>".$results."</table>";