spPager 搜索内容貌似无法分页哦
发布于:2022-01-17 09:50:54
#1 jiayan41
post.php
===============
// 这里使用了spPager,同时用spArgs接受到传入的page参数
$post= spClass("lib_contents");
if( $keyword = $this->spArgs("keyword") ){
$sql = "SELECT * FROM `j_contents` WHERE `type` = 'post' AND `title` LIKE '%$keyword%'" ;
$this->results = $post->spPager($this->spArgs('page', 1), 5)->findSql($sql);
$this->select = spClass("lib_class")->findAll(array("type" => 'post'));
// 这里获取分页数据并发送到smarty模板内
$this->pager = $post->spPager()->getPager();
===============
search.html
===============
=============
搜索到第二页就不再显示数据了,提示有三页,结果只显示第一页的,第二页就不行
2010-04-29 17:38:30
#2 jake
你的那些页码的链接,好像没有传keyword过去吧。比如说下一页
<{spUrl c=post a=search page=$pager.next_page
keyword=$keyword}>
2010-04-29 17:45:07
#3 jiayan41
// 这里使用了spPager,同时用spArgs接受到传入的page参数
$post= spClass("lib_contents");
$keyword = $this->spArgs("keyword");
if( $keyword = $this->spArgs("keyword") ){
$sql = "SELECT * FROM `j_contents` WHERE `type` = 'post' AND `title` LIKE '%$keyword%'" ;
$this->results = $post->spPager($this->spArgs('page', 1), 5)->findSql($sql);
$this->select = spClass("lib_class")->findAll(array("type" => 'post'));
// 这里获取分页数据并发送到smarty模板内
$this->pager = $post->spPager()->getPager();
$this->keyword = $this->spArgs("keyword") ;
=================================================
<{if $pager}>
共有文章<{$pager.total_count}>篇,共有<{$pager.total_page}>页(每页<{$pager.page_size}>篇文章):
<{if $pager.current_page != $pager.first_page}>
前页 |
上一页 |
<{/if}>
<{foreach from=$pager.all_pages item=thepage}>
<{if $thepage != $pager.current_page}>
<{$thepage}> <{else}>
<{$thepage}> <{/if}>
<{/foreach}>
<{if $pager.current_page != $pager.last_page}> |
下一页 |
后页 <{/if}>
<{/if}>
还是不行
2010-04-29 17:55:15
#4 jake
试试把SQL输出来看看。
2010-04-29 17:59:57
#5 jiayan41
LIKE '%����%' 输出SQL之后,找到了问题 ,第二页的时候 字符变成乱码了,所以搜索不到内容,这个也不知道怎么解决
2010-04-29 18:31:31
#6 jake
上面接收的时候,使用urldecode来解码
$keyword = urldecode($this->spArgs("keyword"));
下面发送到模板,使用urlencode来进行URL编码。
$this->keyword = urlencode($keyword);
或者检查一下PHP文件和页面模板是不是都是UTF8.
2010-04-29 20:14:00
#7 jiayan41
// 这里使用了spPager,同时用spArgs接受到传入的page参数
$post= spClass("lib_contents");
$keyword = urldecode($this->spArgs("keyword"));
$sql = "SELECT * FROM `j_contents` WHERE `type` = 'post' AND `title` LIKE '%$keyword%'" ;
$this->results = $post->spPager($this->spArgs('page', 1), 5)->findSql($sql);
echo $post->dumpSql();
$this->pager = $post->spPager()->getPager();
$this->select = spClass("lib_class")->findAll(array("type" => 'post'));
$this->keyword = urlencode($keyword);
咋还是 `title` LIKE '%����%' 我再找找原因吧
2010-04-30 00:07:47
#8 jiayan41
问题很是奇怪,百度,谷歌所有的方法我都试了, 语法也没有问题,估计是我的PHP程序运行在IIS上的问题吧
我明天再试一下。编码能接受,但是接收到的都是乱码,真是奇怪了。
最难受的不是熬夜,不是一天天的搞,而是,问题搞不定心里的那种挫折感太强烈,让人很难受。
希望朋友们都早点睡觉
2010-04-30 01:16:17
#9 jiayan41
PHP的官方网站的urldecode()的说明文档里面看到了:
A reminder: if you are considering using urldecode() on a $_GET variable, DON'T!
Evil PHP:
BAD CODE! DO NOT USE!
$term = urldecode($_GET['sterm']);
?>
Good PHP:
$term = $_GET['sterm'];
?>
The webserver will arrange for $_GET to have been urldecoded once already by the time it reaches you!
Using urldecode() on $_GET can lead to extreme badness, PARTICULARLY when you are assuming "magic quotes" on GET is protecting you against quoting.
Hint: script.php?sterm=%2527 [...]
PHP "receives" this as %27, which your urldecode() will convert to "'" (the singlequote). This may be CATASTROPHIC when injecting into SQL or some PHP functions relying on escaped quotes -- magic quotes rightly cannot detect this and will not protect you!
This "common error" is one of the underlying causes of the Santy.A worm which affects phpBB < 2.0.11.
然后继续挖掘,又Google到这个:
http://bugs.php.net/bug.php?id=29799It's true that nowhere is it mentioned that any variables from outside PHP will be automatically urldecode()'ed... but isn't this expected behaviour? When you pass a variable, whether through POST, GET or Cookies, don't you want that variable to be as it was sent, rather than encoded? I know this might be confusing for people coming from other languages (such as Perl), but doesn't it make sense to have it that way?
现在澄清了:任何来自于外部的变量,都会被自动的urldecode(),包括POST,GET,COOKIES。
还有一些特别的,例如$PHP_SELF
如何禁止系统自动的去做urldecode()?
在 php.ini 设置 magic_quotes_gpc off
2010-04-30 01:28:54
#10 billgame
jake真是一个好人啊,呵呵。
2010-09-30 18:14:25