Php 如何将分页添加到代码中?下一步是什么使分页工作?
在我的代码中,我有这样的Php 如何将分页添加到代码中?下一步是什么使分页工作?,php,class,gridview,pagination,paginate,Php,Class,Gridview,Pagination,Paginate,在我的代码中,我有这样的如何进行分页……… ////////这是我的分页课/////// class simple_pagination { function check_integer($which) { if(isset($_REQUEST[$which])){ if (intval($_REQUEST[$which])>0) { //check the paging variable was se
如何进行分页………
////////这是我的分页课///////
class simple_pagination
{
function check_integer($which) {
if(isset($_REQUEST[$which])){
if (intval($_REQUEST[$which])>0) {
//check the paging variable was set or not,
//if yes then return its number:
//for example: ?page=5, then it will return 5 (integer)
return intval($_REQUEST[$which]);
} else {
return false;
}
}
return false;
}//end of check_integer()
function get_current_page() {
if(($var=$this->check_integer('page'))) {
//return value of 'page', in support to above method
return $var;
} else {
//return 1, if it wasnt set before, page=1
return 1;
}
}//end of method get_current_page()
function doPages($page_size, $thepage, $query_string, $total=0) {
//echo $query_string;exit;
//per page count
$index_limit = 10;
//set the query string to blank, then later attach it with $query_string
$query='';
if(strlen($query_string)>0){
$query = "&".$query_string;
}
//get the current page number example: 3, 4 etc: see above method description
$current = $this->get_current_page();
$total_pages=ceil($total/$page_size);
//echo $total;exit;
$start=max($current-intval($index_limit/2), 1);
$end=$start+$index_limit-1;
echo '<div class="paging">';
if($current==1) {
echo '<span class="prn"> First <<</span> ';
} else {
$i = $current-1;
echo " <a href='$thepage?currentpage=1'>First </a> ";
echo '<a href="'.$thepage.'?page='.$i.$query.'" class="prn" rel="nofollow" title="go to page '.$i.'"><< </a> ';
echo '<span class="prn">...</span> ';
}
if($start > 1) {
$i = 1;
echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a> ';
}
for ($i = $start; $i <= $end && $i <= $total_pages; $i++){
if($i==$current) {
echo '<span>'.$i.'</span> ';
} else {
echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a> ';
}
}
if($total_pages > $end){
$i = $total_pages;
echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a> ';
}
if($current < $total_pages) {
$i = $current+1;
echo '<span class="prn">...</span> ';
echo '<a href="'.$thepage.'?page='.$i.$query.'" class="prn" rel="nofollow" title="go to page '.$i.'"> >> </a> ';
echo " <a href='$thepage?page=$total_pages'>Last </a> ";
} else {
echo '<span class="prn"> Last >></span> ';
}
//if nothing passed to method or zero, then dont print result, else print the total count below:
if ($total != 0){
//prints the total result count just below the paging
echo '<p id="total_count">(total '.$total.' records)</p></div>';
}
}//end of method doPages()
类简单分页
{
函数检查\u整数($which){
如果(isset($\u请求[$which])){
if(intval($_请求[$which])>0){
//检查是否设置了分页变量,
//如果是,则返回其编号:
//例如:?page=5,则返回5(整数)
返回intval($\请求[$which]);
}否则{
返回false;
}
}
返回false;
}//检查结束\u整数()
函数获取当前页面(){
如果($var=$this->check_integer('page')){
//返回“page”的值,以支持上述方法
返回$var;
}否则{
//返回1,如果之前未设置,则第页=1
返回1;
}
}//获取当前页面()的方法结束
函数dopage($page\u size,$thepage,$query\u string,$total=0){
//echo$query\u字符串;退出;
//每页计数
$index_limit=10;
//将查询字符串设置为空,然后使用$query\u字符串附加它
$query='';
if(strlen($query\u string)>0){
$query=“&;”$query\u字符串;
}
//获取当前页码示例:3、4等:参见上述方法说明
$current=$this->获取当前页面();
$total_pages=ceil($total/$page_size);
//echo$total;退出;
$start=max($current intval($index\u limit/2),1);
$end=$start+$index_limit-1;
回声';
如果($current==1){
回声“第一”;
}否则{
$i=$current-1;
回声“;
回声';
回声“…”;
}
如果($start>1){
$i=1;
回声';
}
对于($i=$start;$i$end){
$i=$总页数;
回声';
}
如果($当前<$总页数){
$i=$current+1;
回声“…”;
回声';
回声“;
}否则{
回声“最后”;
}
//如果没有传递到方法或零,则不打印结果,否则打印以下总计数:
如果($total!=0){
//打印页面下方的总结果计数
echo'(总计'$total.'记录)
;
}
}//方法doPages()结束
//////wifi.php/////////
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">Show
<select name="results_page" id= "results_page" onChange="this.form.submit();">
<option value="5" NO >5</option>
<option value="10" NO >10</option>
<option value="20" SELECTED >20</option>
<option value="50" NO >50</option>
</select>
results per page
</form>
<?php
$pagination = new simple_pagination();
$offset = 5;
$array_old = $objquote->viewdata();
$total_records = count($array_old);
$pagination->doPages($offset,$_SERVER['PHP_SELF'], '', $total_records); ?>
如果要从数据库中获取结果/行,则可以使用限制从数据库中获取所选行数
LIMIT子句可用于约束返回的行数
通过SELECT语句
例如:
SELECT * FROM `your_table` LIMIT 0, 10
因此,您可以在表单提交后在SQL查询中设置限制,并将结果循环到diplay
另外,还有一些用于分页的PHP类/教程:
编辑:
SELECT * FROM `your_table` LIMIT 0, 10
在发布有问题的代码后,我们可以看到您在doPages
类中硬编码$index\u limit=10
。您还需要将$index\u limit
传递到doPages
类。如果您从数据库中获取结果/行,您可以使用limit
LIMIT子句可用于约束返回的行数
通过SELECT语句
例如:
SELECT * FROM `your_table` LIMIT 0, 10
因此,您可以在表单提交后在SQL查询中设置限制,并将结果循环到diplay
另外,还有一些用于分页的PHP类/教程:
编辑:
SELECT * FROM `your_table` LIMIT 0, 10
发布您的问题代码后,我们可以看到您在doPages
类中硬编码$index\u limit=10
。您还需要将$index\u limit
传递到doPages
类。您从mysql数据库中获取行吗?这里不欢迎聊天,请花时间键入“请”而不是“plz”。如果你将“plz”从词汇表中分阶段删除,你将在所有在线交易中取得更大成功…@NAVEED是的,我从mysql数据库中获取行。你从mysql数据库中获取行吗?这里不欢迎聊天,请花时间键入“请”而不是“plz”。如果你将“plz”从词汇表中分阶段删除,你将在所有在线交易中取得更大成功…@NAVEED是的,我从mysql数据库中获取行。在标记的onchage事件上写什么?在标记的onchage事件上写什么?