[英]php pagination result Limit per page
Using Simple Dom Parser , I have above 50 result, Now i want result only 10 Per page. 使用Simple Dom Parser,我有50个以上的结果,现在我只希望每页10个结果。 My search.php page have this following code
我的search.php页面具有以下代码
<?php
include('simple_html_dom.php');
$search = $_GET['search'];
$html = file_get_html('http://mysite/'.$search.'.html');
foreach ( $html->find('div#song_html ') as $e ) {
$title= $e->find('div', 2)->plaintext;
echo $title.'<br>';
}
?>
Now i calling my page using this code show all above 50 result .. 现在,我使用此代码调用我的页面,显示所有高于50的结果..
http://domain/search.php?search=Keyword
I want per page 10 result Like &startrow=1 means first 10 result &startrow=2 means second 10 result 我要每页显示10个结果,例如&startrow = 1表示前10个结果&startrow = 2表示第二个10个结果
http://domain/search.php?search=Keyword&startrow=1 //page 1 with 10 result
http://domain/search.php?search=Keyword&startrow=2 //page 2 with Next 10 result
http://domain/search.php?search=Keyword&startrow=3 //page 3 with Next 10 result
You could work with array_slice()
on the result of the DOM parser... Something like the following code could do the trick (untested code): 您可以在DOM解析器的结果上使用
array_slice()
...像下面的代码一样可以解决问题(未经测试的代码):
<?php
include('simple_html_dom.php');
$page = array_key_exists('startrow', $_GET) ? (int)$_GET['startrow'] : 1;
$search = $_GET['search'];
$html = file_get_html('http://mysite/'.$search.'.html');
$songs = $html->find('div#song_html ');
$paginationStart = min((10 * ((int)$page - 1)), (count($songs)-1));
$results = array_slice($songs, $paginationStart, 10);
foreach ( $results as $e ) {
$title= $e->find('div', 2)->plaintext;
echo $title.'<br>';
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.