区别就是在做搜索显示的时候加入 WHERE $typename LIKE '$keyname%'条件帅选分页显示,没有搜索的时候按照分页显示所有记录
问题就是搜索分页显示没问题,但是链接有问题,点击下一页的时候会跳到按照没有搜索的条件按照分页显示。
请教各位看看是什么原因。谢谢啊引用页面:if(($_GET['action']=="search")&&($_GET['type'])&&($_GET['keyword']))
{
ppssearchreturn($_GET['type'],$_GET['keyword']);
}
else
//if(($_GET['action']=="search")&&($_GET['type'])&&($_GET['keyword']))
if(!isset($_GET['action']))
{
//echo"No";
ppssearchreturn("","");
}
function ppssearchreturn($typename,$keyname)
{
$pagesize=30; //define the page show number
$page=isset($_GET["page"])?intval($_GET["page"]):1; //define the page default value;if null page=1,
if($typename!=''&&$keyname!='')
{
$searchsql=mysql_query("select PCBNB from propertyrecord WHERE $typename LIKE '$keyname%'")or die("Please confirm the search item!".mysql_error());
}
else
$searchsql=mysql_query("select PCBNB from propertyrecord")or die("Please confirm the search item!".mysql_error());
$total=mysql_num_rows($searchsql);
$pagecount=ceil($total/$pagesize); //totle pages
if ($page>$pagecount)
{
$page=$pagecount;//check
}
if ($page<=0)
{
$page=1;
}
$offset=($page-1)*$pagesize; //offset page
$pre=$page-1; //preious page
$next=$page+1; //next page
$first=1; //the first page
$last=$pagecount; //the last page
if($typename!=''&&$keyname!='')
{
$exec="select * from propertyrecord WHERE $typename LIKE '$keyname%' order by ID desc limit $offset,$pagesize"; //query====the data array deside by the chose
}
else
$exec="select * from propertyrecord order by ID desc limit $offset,$pagesize"; //query====the data array deside by the chose
$result=mysql_query($exec);
//mysql_data_seek($result,0);
while($row=mysql_fetch_array($result))
{
echo "<tr onmouseover=\"this.style.backgroundColor='#EEEEEE'\" onmouseout=\"this.style.backgroundColor='#FFFFFF'\">\n";
echo "<td class=xl48 nowrap align=\"center\"><a href=\"showproperty.php?action=show&item=pcbnb&pcbnb=$row[PCBNB]\">$row[PCBNB]</a></td>\n";
echo "<td class=xl48 nowrap align=\"left\">$row[PROJECTNAME]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[GERBERDATE]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[EDATP]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[COMC]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[PINC]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[CONNEC]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[LAYERC]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[PTYPE]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[TOOLVER]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[LAYOUT]</td>\n";
}
echo "</tr>\n";echo "<tr class=xl3329962 align=\"middle\">";
echo "<a href=\"?page=1\">[First]</a>";
echo "<a href=\"?page=$pre\">[Previous]</a>";
echo "<a href=\"?page=$next\">[Next]</a>";
echo "<a href=\"?page=$last\">[Last]</a>";
echo $page."/".$pagecount." Totle ".$total." records";
echo "</tr>";
}
问题就是搜索分页显示没问题,但是链接有问题,点击下一页的时候会跳到按照没有搜索的条件按照分页显示。
请教各位看看是什么原因。谢谢啊引用页面:if(($_GET['action']=="search")&&($_GET['type'])&&($_GET['keyword']))
{
ppssearchreturn($_GET['type'],$_GET['keyword']);
}
else
//if(($_GET['action']=="search")&&($_GET['type'])&&($_GET['keyword']))
if(!isset($_GET['action']))
{
//echo"No";
ppssearchreturn("","");
}
function ppssearchreturn($typename,$keyname)
{
$pagesize=30; //define the page show number
$page=isset($_GET["page"])?intval($_GET["page"]):1; //define the page default value;if null page=1,
if($typename!=''&&$keyname!='')
{
$searchsql=mysql_query("select PCBNB from propertyrecord WHERE $typename LIKE '$keyname%'")or die("Please confirm the search item!".mysql_error());
}
else
$searchsql=mysql_query("select PCBNB from propertyrecord")or die("Please confirm the search item!".mysql_error());
$total=mysql_num_rows($searchsql);
$pagecount=ceil($total/$pagesize); //totle pages
if ($page>$pagecount)
{
$page=$pagecount;//check
}
if ($page<=0)
{
$page=1;
}
$offset=($page-1)*$pagesize; //offset page
$pre=$page-1; //preious page
$next=$page+1; //next page
$first=1; //the first page
$last=$pagecount; //the last page
if($typename!=''&&$keyname!='')
{
$exec="select * from propertyrecord WHERE $typename LIKE '$keyname%' order by ID desc limit $offset,$pagesize"; //query====the data array deside by the chose
}
else
$exec="select * from propertyrecord order by ID desc limit $offset,$pagesize"; //query====the data array deside by the chose
$result=mysql_query($exec);
//mysql_data_seek($result,0);
while($row=mysql_fetch_array($result))
{
echo "<tr onmouseover=\"this.style.backgroundColor='#EEEEEE'\" onmouseout=\"this.style.backgroundColor='#FFFFFF'\">\n";
echo "<td class=xl48 nowrap align=\"center\"><a href=\"showproperty.php?action=show&item=pcbnb&pcbnb=$row[PCBNB]\">$row[PCBNB]</a></td>\n";
echo "<td class=xl48 nowrap align=\"left\">$row[PROJECTNAME]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[GERBERDATE]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[EDATP]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[COMC]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[PINC]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[CONNEC]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[LAYERC]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[PTYPE]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[TOOLVER]</td>\n";
echo "<td class=xl48 nowrap align=\"center\">$row[LAYOUT]</td>\n";
}
echo "</tr>\n";echo "<tr class=xl3329962 align=\"middle\">";
echo "<a href=\"?page=1\">[First]</a>";
echo "<a href=\"?page=$pre\">[Previous]</a>";
echo "<a href=\"?page=$next\">[Next]</a>";
echo "<a href=\"?page=$last\">[Last]</a>";
echo $page."/".$pagecount." Totle ".$total." records";
echo "</tr>";
}
解决方案 »
- $_SERVER['http_referer']无效
- php初学都在线等待一个菜鸟问题,急急急!!!!!!!!!!!!!!!!!
- 怎么我键入控制器名/action 出现 object not found
- php如何实现cer证书的导入
- 问个低级问题?
- 关于PHP的问题,大虾帮下忙哦。急
- IE里面怎么实现选中一块区域看它的源码?
- frame把窗口问题?
- 我在使用表单时遇到困难,用两个下拉列表接受用户选择的国家和省份,两个下拉列表分别是调用数据库中的内容,请问:如何使得选择某个国家的同
- 求助,php怎么在不改变分辨率的情况下更大的压缩png格式的图片啊
- 有请唠叨,关于smarttemplate
- 关于在父页面设定从子页面传过来的值
{
if($_GET['type'])&&($_GET['keyword']){
setCookie("type",$_GET['type']);
setCookie("keyword",$_GET['keyword']);
ppssearchreturn($_GET['type'],$_GET['keyword']);
}
elseif($_COOKIE['type'] && $_COOKIE['keyword']){
ppssearchreturn($_COOKIE['type'],$_COOKIE['keyword']);
}
}
...
..
if( $_GET['action']=="search")
{
if($_GET['type'] && $_GET['keyword']){
setCookie("type",$_GET['type']);
setCookie("keyword",$_GET['keyword']);
ppssearchreturn($_GET['type'],$_GET['keyword']);
}
elseif($_COOKIE['type'] && $_COOKIE['keyword']){
ppssearchreturn($_COOKIE['type'],$_COOKIE['keyword']);
}
}
...
..
相当于
if(!isset($_GET['action'])||$_GET['action']=="search")
{判断}
echo "<tr class=xl3329962 align=\"middle\">";
echo "<a href=\"?page=1\">[First]</a>";
echo "<a href=\"?page=$pre\">[Previous]</a>";
echo "<a href=\"?page=$next\">[Next]</a>";//分页这样不行的,比如本页url中有a=1&b=2&c=3这样的query_string,你得保证下一页也能获取,要不你一分页光把页数变了.
echo "<a href=\"?page=$last\">[Last]</a>";
echo $page."/".$pagecount." Totle ".$total." records";
echo "</tr>";
function getPageUrl($page,$url = '',$page_name = 'page')
{
if ($url == '') $url = '?';
$arr_url = array_merge($_GET,$_POST);
$arr_url[$page_name] = $page;
return $url.http_build_query($arr_url);
}$pre = 5;
echo "<a href=\"".getPageUrl(1)."\">[First]</a>";
echo "<a href=\"".getPageUrl($pre)."\">[Previous]</a>";
/*
分页类
$cur_page:当前页码
$total_page:总共页数
$record_nums:每页显示行数
$class_id:资源的类id,查数据库
*/
include_once("DataBase.php");
class separatepage{
var $cur_page=0;
var $total_page=0;
var $record_nums = 0;
var $class_id=0;
var $db_obj=null;
var $page_url="";
function __construct($current_page,$rec_num,$cid,$db_name,$url){
$this->cur_page = $current_page;
$this->record_nums = $rec_num;
$this->class_id = $cid;
$this->page_url = $url;
$this->db_obj = new db($db_name);
}
function setUrl($url){
$this->page_url = $url;
}
function getTotalRecords(){
$sql = "select count(distinct id) as total from t_source where classid=".$this->class_id;
$conn = $this->db_obj->getConn();
$result = $this->db_obj->query($conn,$sql);
if($row = mysql_fetch_array($result)){
return $row["total"];
}
$this->db_obj->close_con($conn);
}
function getSeparatePageInfo(){
$this->total_page = ceil($this->getTotalRecords()/$this->record_nums);
$npage = $this->cur_page+1;
$ppage = $this->cur_page-1;
$pageInfo.= $this->cur_page==1 ? "<div class='bot'><a href='".$this->page_url."?id=".$this->class_id."&page=".$npage."';\"><img src='images/nextpage.gif' width='60px' height='18px' border='0'></a></div>" : "";
$pageInfo.= $this->cur_page==$this->total_page ? "<div class='bot'><a href='".$this->page_url."?id=".$this->class_id."&page=".$ppage."';\"><img src='images/lastpage.gif' width='60px' height='18px' border='0'></a></div>" : "";
if($this->cur_page>1&&$this->cur_page<$this->total_page){
$pageInfo.= "<div class='bot'><a href='".$this->page_url."?id=".$this->class_id."&page=".$npage."';\"><img src='images/nextpage.gif' width='60px' height='18px' border='0'></a></div><div class='bot'><a href='".$this->page_url."?id=".$this->class_id."&page=".$ppage."';\"><img src='images/lastpage.gif' width='60px' height='18px' border='0'></a></div>";
}
$pageInfo.= "<div class='pot'>页次: ".$this->cur_page."/".$this->total_page."</div>";
if($this->total_page==1){
$pageInfo="";
}
return $pageInfo;
}
}
?>
<?php
/**
* filename: page.class.php
* @package:phpbean
* @author :YuChao(yuchao86#gmail.com>
* @copyright :Copyright 2009 YuChao
* @license:version 2.0
* @create:2009-9-8
* @modify:2009-9-8
* @modify:YuChao 2009-9-9
* description:超强分页类,四种分页模式,默认采用类似baidu,google的分页风格。
* 2.0增加功能:支持自定义风格,自定义样式,同时支持PHP4和PHP5,
* to see detail,please visit http://www.phpobject.net/blog/read.php
* example:
* 模式四种分页模式:
require_once('../libs/classes/page.class.php');
$page=new page(array('total'=>1000,'perpage'=>20));
echo 'mode:1<br>'.$page->show();
echo '<hr>mode:2<br>'.$page->show(2);
echo '<hr>mode:3<br>'.$page->show(3);
echo '<hr>mode:4<br>'.$page->show(4);
开启AJAX:
$ajaxpage=new page(array('total'=>1000,'perpage'=>20,'ajax'=>'ajax_page','page_name'=>'test'));
echo 'mode:1<br>'.$ajaxpage->show();
采用继承自定义分页显示模式:
demo:http://www.phpobject.net/blog
*/
class page {
/**
* config ,public
*/
public $page_name = "page"; //page标签,用来控制url页。比如说xxx.php?PB_page=2中的PB_page
public $next_page = '>'; //下一页
public $pre_page = '<'; //上一页
public $first_page = 'First'; //首页
public $last_page = 'Last'; //尾页
public $pre_bar = '<<'; //上一分页条
public $next_bar = '>>'; //下一分页条
public $format_left = '[';
public $format_right = ']';
public $is_ajax = false; //是否支持AJAX分页模式
/**
* private
*
*/
public $pagebarnum = 10; //控制记录条的个数。
public $totalpage = 0; //总页数
public $ajax_action_name = ''; //AJAX动作名
public $nowindex = 1; //当前页
public $url = ""; //url地址头
public $offset = 0;
/**
* constructor构造函数
*
* @param array $array['total'],$array['perpage'],$array['nowindex'],$array['url'],$array['ajax']...
*/
function page($array) {
if (is_array ( $array )) {
if (! array_key_exists ( 'total', $array ))
$this->error ( __FUNCTION__, 'need a param of total' );
$total = intval ( $array ['total'] );
$perpage = (array_key_exists ( 'perpage', $array )) ? intval ( $array ['perpage'] ) : 10;
$nowindex = (array_key_exists ( 'nowindex', $array )) ? intval ( $array ['nowindex'] ) : '';
$url = (array_key_exists ( 'url', $array )) ? $array ['url'] : '';
} else {
$total = $array;
$perpage = 10;
$nowindex = '';
$url = '';
}
if ((! is_int ( $total )) || ($total < 0))
$this->error ( __FUNCTION__, $total . ' is not a positive integer!' );
if ((! is_int ( $perpage )) || ($perpage <= 0))
$this->error ( __FUNCTION__, $perpage . ' is not a positive integer!' );
if (! empty ( $array ['page_name'] ))
$this->set ( 'page_name', $array ['page_name'] ); //设置pagename
$this->_set_nowindex ( $nowindex ); //设置当前页
$this->_set_url ( $url ); //设置链接地址
$this->totalpage = ceil ( $total / $perpage );
$this->offset = ($this->nowindex - 1) * $perpage;
if (! empty ( $array ['ajax'] ))
$this->open_ajax ( $array ['ajax'] ); //打开AJAX模式
}
/**
* 设定类中指定变量名的值,如果改变量不属于这个类,将throw一个exception
*
* @param string $var
* @param string $value
*/
function set($var, $value) {
if (in_array ( $var, get_object_vars ( $this ) ))
$this->$var = $value;
else {
$this->error ( __FUNCTION__, $var . " does not belong to PB_Page!" );
}
}
/**
* 打开倒AJAX模式
*
* @param string $action 默认ajax触发的动作。
*/
function open_ajax($action) {
$this->is_ajax = true;
$this->ajax_action_name = $action;
}
/**
* 获取显示"下一页"的代码
*
* @param string $style
* @return string
*/
function next_page($style = '') {
if ($this->nowindex < $this->totalpage) {
return $this->_get_link ( $this->_get_url ( $this->nowindex + 1 ), $this->next_page, $style );
}
return '<span class="' . $style . '">' . $this->next_page . '</span>';
}
/**
* 获取显示“上一页”的代码
*
* @param string $style
* @return string
*/
function pre_page($style = '') {
if ($this->nowindex > 1) {
return $this->_get_link ( $this->_get_url ( $this->nowindex - 1 ), $this->pre_page, $style );
}
return '<span class="' . $style . '">' . $this->pre_page . '</span>';
}
/**
* 获取显示“首页”的代码
*
* @return string
*/
function first_page($style = '') {
if ($this->nowindex == 1) {
return '<span class="' . $style . '">' . $this->first_page . '</span>';
}
return $this->_get_link ( $this->_get_url ( 1 ), $this->first_page, $style );
}
?>
* 获取显示“尾页”的代码
*
* @return string
*/
function last_page($style = '') {
if ($this->nowindex == $this->totalpage) {
return '<span class="' . $style . '">' . $this->last_page . '</span>';
}
return $this->_get_link ( $this->_get_url ( $this->totalpage ), $this->last_page, $style );
}
function nowbar($style = '', $nowindex_style = '') {
$plus = ceil ( $this->pagebarnum / 2 );
if ($this->pagebarnum - $plus + $this->nowindex > $this->totalpage)
$plus = ($this->pagebarnum - $this->totalpage + $this->nowindex);
$begin = $this->nowindex - $plus + 1;
$begin = ($begin >= 1) ? $begin : 1;
$return = '';
for($i = $begin; $i < $begin + $this->pagebarnum; $i ++) {
if ($i <= $this->totalpage) {
if ($i != $this->nowindex)
$return .= $this->_get_text ( $this->_get_link ( $this->_get_url ( $i ), $i, $style ) );
else
$return .= $this->_get_text ( '<span class="' . $nowindex_style . '">' . $i . '</span>' );
} else {
break;
}
$return .= "\n";
}
unset ( $begin );
return $return;
}
/**
* 获取显示跳转按钮的代码
*
* @return string
*/
function select() {
$return = '<select name="PB_Page_Select">';
for($i = 1; $i <= $this->totalpage; $i ++) {
if ($i == $this->nowindex) {
$return .= '<option value="' . $i . '" selected>' . $i . '</option>';
} else {
$return .= '<option value="' . $i . '">' . $i . '</option>';
}
}
unset ( $i );
$return .= '</select>';
return $return;
}
/**
* 获取mysql 语句中limit需要的值
*
* @return string
*/
function offset() {
return $this->offset;
}
/**
* 控制分页显示风格(你可以增加相应的风格)
*
* @param int $mode
* @return string
*/
function show($mode = 1) {
switch ($mode) {
case '1' :
$this->next_page = '下一页';
$this->pre_page = '上一页';
return $this->pre_page () . $this->nowbar () . $this->next_page () . '第' . $this->select () . '页';
break;
case '2' :
$this->next_page = '下一页';
$this->pre_page = '上一页';
$this->first_page = '首页';
$this->last_page = '尾页';
return $this->first_page () . $this->pre_page () . '[第' . $this->nowindex . '页]' . $this->next_page () . $this->last_page () . '第' . $this->select () . '页';
break;
case '3' :
$this->next_page = '下一页';
$this->pre_page = '上一页';
$this->first_page = '首页';
$this->last_page = '尾页';
return $this->first_page () . $this->pre_page () . $this->next_page () . $this->last_page ();
break;
case '4' :
$this->next_page = '下一页';
$this->pre_page = '上一页';
return $this->pre_page () . $this->nowbar () . $this->next_page ();
break;
case '5' :
return $this->pre_bar () . $this->pre_page () . $this->nowbar () . $this->next_page () . $this->next_bar ();
break;
}
}
/*----------------private function (私有方法)-----------------------------------------------------------*/
/**
* 设置url头地址
* @param: String $url
* @return boolean
*/
function _set_url($url = "") {
if (! empty ( $url )) {
//手动设置
$this->url = $url . ((stristr ( $url, '?' )) ? '&' : '?') . $this->page_name . "=";
} else {
//自动获取
if (empty ( $_SERVER ['QUERY_STRING'] )) {
//不存在QUERY_STRING时
$this->url = $_SERVER ['REQUEST_URI'] . "?" . $this->page_name . "=";
} else {
//
if (stristr ( $_SERVER ['QUERY_STRING'], $this->page_name . '=' )) {
//地址存在页面参数
$this->url = str_replace ( $this->page_name . '=' . $this->nowindex, '', $_SERVER ['REQUEST_URI'] );
$last = $this->url [strlen ( $this->url ) - 1];
if ($last == '?' || $last == '&') {
$this->url .= $this->page_name . "=";
} else {
$this->url .= '&' . $this->page_name . "=";
}
} else {
//
$this->url = $_SERVER ['REQUEST_URI'] . '&' . $this->page_name . '=';
} //end if
} //end if
} //end if
}
/**
* 设置当前页面
*
*/
function _set_nowindex($nowindex) {
if (empty ( $nowindex )) {
//系统获取
if (isset ( $_GET [$this->page_name] )) {
$this->nowindex = intval ( $_GET [$this->page_name] );
}
} else {
//手动设置
$this->nowindex = intval ( $nowindex );
}
}
/* function _set_nowindex()
{
if(isset($_GET[$this->page_name]))
{
$this->nowindex=intval($_GET[$this->page_name]);
}
}*/
/**
* 为指定的页面返回地址值
*
* @param int $pageno
* @return string $url
*/
function _get_url($pageno = 1) {
return $this->url . $pageno;
}
/**
* 获取分页显示文字,比如说默认情况下_get_text('<a href="">1</a>')将返回[<a href="">1</a>]
*
* @param String $str
* @return string $url
*/
function _get_text($str) {
return $this->format_left . $str . $this->format_right;
}
/**
* 获取链接地址
*/
function _get_link($url, $text, $style = '') {
$style = (empty ( $style )) ? '' : 'class="' . $style . '"';
if ($this->is_ajax) {
//如果是使用AJAX模式
return '<a ' . $style . ' href="javascript:' . $this->ajax_action_name . '(\'' . $url . '\')">' . $text . '</a>';
} else {
return '<a ' . $style . ' href="' . $url . '">' . $text . '</a>';
}
}
/**
* 出错处理方式
*/
function error($function, $errormsg) {
die ( 'Error in file <b>' . __FILE__ . '</b> ,Function <b>' . $function . '()</b> :' . $errormsg );
}
}
/*************************************************************
作者:YuChao
联系方式:[email protected]
工作单位:北京纳吉兴保健食品有限公司
申明:本软件不属于开源软件,是本公司根据自己需求自己创作的软件
在得到公司许可的情况下,并且遵守GPL的条件下准予重新发布
**************************************************************
*/
有兴趣看一下我写的哦呵呵还有楼主貌似没写查询条件查询条件是必须的哦呵呵
http://topic.csdn.net/u/20090929/09/0c0a6e1d-6e8b-4673-bf55-af886ddf1a2f.html?83719
解决方法就是在echo "<a href=\"?page=1\">[First]</a>";
echo "<a href=\"?page=$pre\">[Previous]</a>";
echo "<a href=\"?page=$next\">[Next]</a>";
echo "<a href=\"?page=$last\">[Last]</a>";跳转的条件上加上?action=search&type=&keyword=&page1.2.