Yahoo Boss API分页?

时间:2015-02-19 14:20:14

标签: php json pagination yahoo-api yahoo-boss-api

我使用php中的代码连接到api并显示结果......

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require("OAuth.php"); 
    $cc_key  = "cc_key"; //cc_key
    $cc_secret = "cc_secret"; // cc_secret key
    $url = "https://yboss.yahooapis.com/ysearch/web";
    $args = array();
    $args["q"] = htmlspecialchars($_GET["q"]);
    $args["format"] = "json";
    $consumer = new OAuthConsumer($cc_key, $cc_secret);
    $request = OAuthRequest::from_consumer_and_token($consumer, NULL,"GET", $url, $args);
    $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);
    $url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args));
    //echo $url . "<br>"; test uri
    $ch = curl_init();
    $headers = array($request->to_header());
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $rsp = curl_exec($ch);
    $results = json_decode($rsp, true);

//force to assoc-array, which will allow array-access
foreach($results['bossresponse']['web']['results'] as $result)
{
    //$result is array here, but do the same stuff
echo '<a href="'.$result['url'].'" target=\'_blank\'>'.$result['title'].'</a></br>';
echo ''.$result['abstract'].'</br>';
echo '<a href="'.$result['url'].'" target=\'_blank\'>'.$result['dispurl'].'</a></br>';

}
?>

然后写迷你&#34;分页&#34;

//$start = "&start=" . "0";
$start_val = $_GET['start'];
if ($start_val == "") $start_val = 0;
$start = "&start=" . $start_val;
// Some more code...
$count_val = 10;
$count = "&count=" . $count_val;

if ($query != "") {
if ($start_val != 0) {
echo '<a href="?query='.$_GET['query'] . '&start='. (intval($start_val) - intval($count_val))  .'">previous</a>';
echo '<span> | </span>';
}
echo '<a href="?query='.$_GET['query'] . '&start='.(intval($start_val) + intval($count_val)) . '">next</a>';
}

但是&#34;分页&#34;不起作用=( 我无法理解为什么不起作用

我的问题是如何对结果进行分页,因为所有50个结果仅显示在第一个网页上。我想在每个页面显示十个结果。

请帮助我

感谢。

0 个答案:

没有答案