倒序排列

#1 zylmlnh


<{foreach from=$aaa item=one}>

  
   
   
   

<{/foreach}>
<{$one.id}><{$one.name}><{$one.title}><{$one.contents}>


怎么样让他倒序列排列

2011-01-03 21:44:42

#2 jake

比较难实现,只能通过自定义模板函数来进行数组的倒序。

一般而言,view层模板中仅作为显示逻辑,而数据排序那应该是m层model的工作,直接给输出的结果加个排序并不是很复杂的事情。

2011-01-03 22:08:20

#3 zylmlnh

直接给输出的结果加个排序并不是很复杂的事情。
class jzren extends spModel
{
  var $pk = "id"; // 每个留言唯一的标志,可以称为主键
  var $table = "user"; // 数据表的名称
}
?>
怎么实现呢?

2011-01-03 22:38:20

#4 jake

可以参考手册关于find/findAll排序的说明
http://speedphp.com/post/model-select.html

或者可以直接使用PHP的rsort函数,令数组反转过来
http://cn2.php.net/manual/en/function.rsort.php

2011-01-04 08:39:01

#5 zylmlnh

class main extends spController
{
        function index(){ // 这里是首页
                $tpl = $this->spArgs("tpl", "green"); // 这里接收tpl参数,使得模板变化
                $guestbook = spClass("guestbook");
        $this->aaa = $guestbook->findAll();
                                $this->display("{$tpl}/index.html");
        }
        function write(){ // 这里是留言
                $guestbook = spClass("guestbook");
                $newrow = array( // 这里制作新增记录的值
                'name' => $this->spArgs('name'),
                'title' => $this->spArgs('title'), // 从spArgs获取到表单提交上来的title
                'contents' => $this->spArgs('contents'),
                );
                $guestbook->create($newrow);
                echo "留言成功,返回";
        }
}

------------
具体怎么写呢
谁帮我写下

2011-01-04 13:26:50

#6 jake

$this->aaa = $guestbook->findAll();
改成
$this->aaa = $guestbook->findAll(null, 'id DESC');

guestbook的主键应该是id吧

2011-01-04 13:30:23

#7 zylmlnh

是的
谢谢你了

2011-01-04 14:11:14

#8 zylmlnh

SELECT * FROM guestbook ORDER BY id DESC LIMIT 0 , 10

查询最新的10条记录

$this->aaa = $guestbook->findAll(null, null, " post_time DESC  ", " 10 ");
$this->aaa = $guestbook->findAll(null, " post_time DESC  ", " 10 ");
都报错为什么呢?

2011-01-04 14:32:45

#9 zylmlnh

好了.
问题解决了

2011-01-04 14:51:08