bing json api在PHP中的分页 [英] bing json api pagination in PHP
问题描述
请尝试自定义一个使用Bing API的搜索项目,这里的挑战是结果不是Paginated,而是有一个Load More我想改成分页,请问我该如何去关于它?我的代码如下:
<?php
include(" ../ includes / config.php");
include("../ includes / functions.php");
mysql_connect($ conf ['host'],$ conf ['user'],$ conf ['pass']);
mysql_query('SET NAMES utf8');
mysql_select_db($ conf ['name']);
$ confUrl = $ conf ['url'];
$ resultSettings = mysql_fetch_row(mysql_query(getSettings($ querySettings)));
if(isset($ _ POST ['loadmore'])){
$ request = str_replace(array('\\','https:// api) .datamarket.azure.com / Data.ashx / Bing / Search / Web?Query ='),array('','https://api.datamarket.azure.com/Bing/Search/Web?$format=json&& ; Query ='),$ _POST ['loadmore']);
$ process = curl_init($ request);
curl_setopt($ process,CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
curl_setopt($ process,CURLOPT_USERPWD,$ resultSettings [1]。":"。$ resultSettings [1]);
curl_setopt($ process,CURLOPT_TIMEOUT,30);
curl_setopt($ process,CURLOPT_RETURNTRANSFER,TRUE);
$ response = curl_exec($ process);
curl_close($ process);
$ jsonobj = json_decode($ response);
foreach($ jsonobj-> d->结果为$ value){
$ title ='< a href ="'。$ value-> Url。' "目标= QUOT;" [链路"]" $ _ COOKIE。"。";>" $值 - >名称"< / A> ";
$ url = highlightKeyword($ value-> DisplayUrl);
$ desc = highlightKeyword($ value-> Description);
//更多来自...
$ find ='site:';
$ more = strpos($ _ POST ['u'],$ find);
if($ more === false){
$ hostUrl = parse_url($ value-> Url);
$ moreurl ='< a href ="'。$ confUrl。'/?a = web& q ='。$ _ POST ['p']。'site:'。$ hostUrl ['host' ]。'">更多来自'。$ hostUrl ['host']。'< / a>';
}其他{
$ moreurl ='';
}
$ domain = parse_url($ value-> Url);
echo'< div class =" result_c">
< div class =" results_title">< h3>'。highlightingKeyword($ title)。'< / h3>< / div>
< div class =" results_url">'。$ url。'< / div>
< div class =" results_description">'。$ desc。'< / div>
< div class =" results_more">'。$ moreurl。'< / div>
< / div>';
}
}
if(!empty($ jsonobj-> d-> __ next)){
echo
'< div class =" morebox" ;>
< button type =" button" class =" btn btn-primary" id ="'。$ jsonobj-> d-> __ next。'">加载更多< / button>
< / div>';
}
mysql_close();
?>
看一下代码的结尾你会发现加载更多而不是分页,请问怎么做我将其更改为更好的分页,加载到另一个页面并在那里显示进一步的结果?谢谢
你好。
看来这个问题是特定于PHP的,不一定是一个微软的服务或技术,这是正确的吗?在这种情况下,我建议你尝试一个关于分页主题的PHP论坛或教程。例如,这里有一个相关的:
http://www.phpfreaks。 com / tutorial / basic-pagination
我希望这会有所帮助!
Eric
Please am trying to customized a Search Project that utilizes the Bing API and the challenge here is that the result is not Paginated but rather has a Load More which I want to change to a pagination, Please how do I go about it? My codes are below:
<?php include("../includes/config.php"); include("../includes/functions.php"); mysql_connect($conf['host'], $conf['user'], $conf['pass']); mysql_query('SET NAMES utf8'); mysql_select_db($conf['name']); $confUrl = $conf['url']; $resultSettings = mysql_fetch_row(mysql_query(getSettings($querySettings))); if(isset($_POST['loadmore'])) { $request = str_replace(array('\\', 'https://api.datamarket.azure.com/Data.ashx/Bing/Search/Web?Query='), array('', 'https://api.datamarket.azure.com/Bing/Search/Web?$format=json&Query='), $_POST['loadmore']); $process = curl_init($request); curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($process, CURLOPT_USERPWD, $resultSettings[1] . ":" . $resultSettings[1]); curl_setopt($process, CURLOPT_TIMEOUT, 30); curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($process); curl_close($process); $jsonobj = json_decode($response); foreach($jsonobj->d->results as $value) { $title = '<a href="'.$value->Url.'" target="'.$_COOKIE['link'].'">'.$value->Title.'</a> '; $url = highlightKeyword($value->DisplayUrl); $desc = highlightKeyword($value->Description); // More from... $find = 'site:'; $more = strpos($_POST['u'], $find); if($more === false) { $hostUrl = parse_url($value->Url); $moreurl = '<a href="'.$confUrl.'/?a=web&q='.$_POST['p'].' site:'.$hostUrl['host'].'">more from '.$hostUrl['host'].'</a>'; } else { $moreurl = ''; } $domain = parse_url($value->Url); echo '<div class="result_c"> <div class="results_title"><h3>'.highlightKeyword($title).'</h3></div> <div class="results_url">'.$url.'</div> <div class="results_description">'.$desc.'</div> <div class="results_more">'.$moreurl.'</div> </div>'; } } if(!empty($jsonobj->d->__next)) { echo '<div class="morebox"> <button type="button" class="btn btn-primary" id="'.$jsonobj->d->__next.'">Load More</button> </div>'; } mysql_close(); ?>
Looking at the end of the code you will find a Load more instead of a Pagination, Please how do I change it to a better pagination that loads to another page and shows further results there? Thanks
Hello.
It seems this question is specific to PHP and not necessarily to a Microsoft service or technology, is that correct? In that case I suggest you try a PHP forum or tutorial on the subject of pagination. For example here is one that appears related:
http://www.phpfreaks.com/tutorial/basic-pagination
I hope this helps!
Eric
这篇关于bing json api在PHP中的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!