Zend_db& Zend_paginator - 没有一个有趣的时间

时间:2009-06-11 19:13:25

标签: php zend-framework zend-paginator

我遇到了一个严重的问题,将我的'select'语句转换为可以与zend paginator一起使用的东西...有人可以解决它,因为我没有运气......

这是我的问题:

$query = "SELECT
            user_id, name, gender, city, province, country, image_id, one_liner, self_description, reputation
          FROM
            users
          WHERE
          (
            (69.1 * (latitude - " . $user->latitude . ")) * 
            (69.1 * (latitude - " . $user->latitude . "))
          ) + ( 
            (69.1 * (longitude - " . $user->longitude . ") * COS(" . $user->latitude . " / 57.3)) * 
            (69.1 * (longitude - " . $user->longitude . ") * COS(" . $user->latitude . " / 57.3))
          ) < " . pow($radius, 2) . " 
          ORDER BY 
          (
                (69.1 * (latitude - " . $user->latitude . ")) * 
            (69.1 * (latitude - " . $user->latitude . "))
          ) + ( 
            (69.1 * (longitude - " . $user->longitude . ") * COS(" . $user->latitude . " / 57.3)) * 
            (69.1 * (longitude - " . $user->longitude . ") * COS(" . $user->latitude . " / 57.3))

这是我到目前为止所做的:

        $select = $db->select();
        $select->from(
            array('users'),
                array(
                        'user_id', 
                        'name', 
                        'gender', 
                        'city', 
                        'province', 
                        'country', 
                        'image_id', 
                        'one_liner', 
                        'self_description', 
                        'reputation'
                    )
        );
        $select->where("(69.1 * (latitude - " . $user->latitude . ")) * (69.1 * (latitude - " . $user->latitude . "))) + ((69.1 * (longitude - " . $user->longitude . ") * COS(" . $user->latitude . " / 57.3)) * (69.1 * (longitude - " . $user->longitude . ") * COS(" . $user->latitude . " / 57.3))) < " . pow($radius, 2));
        $select->order("(69.1 * (latitude - " . $user->latitude . ")) * (69.1 * (latitude - " . $user->latitude . "))) + ((69.1 * (longitude - " . $user->longitude . ") * COS(" . $user->latitude . " / 57.3)) * (69.1 * (longitude - " . $user->longitude . ") * COS(" . $user->latitude . " / 57.3))) ASC");

3 个答案:

答案 0 :(得分:1)

为什么你有“&lt;”在你的订单条款中?

答案 1 :(得分:1)

这与Zend_Paginator有什么关系?啊,你有查询,你不知道如何用它创建一个paginator,或者paginator不使用这个查询?

我唯一能看到的是你在where()order()条款中缺少一个左括号:

$select->where("((69.1 * [...] ");
$select->order("((69.1 * [...] ");
                 ^

因此,可能Zend_Paginator无法正常工作,因为SQL查询有错误?

当然,我必须问:你插入的变量是安全的,还是真的应该使用$db->quote($user->latitude, Zend_Db::FLOAT_TYPE)

答案 2 :(得分:0)

假设您正在使用MVC模式,这不会起作用吗?

在你的引导程序中:

Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');

在您的控制器中:

$page = Zend_Paginator::factory($select);
$page->setCurrentPageNumber($this->_getParam('page', 1));
$page->setItemCountPerPage($this->_getParam('par', 20));
$this->view->results= $page;
在您看来

<?php foreach($this->results as $result) : ?>
    <!-- print some $result stuff here -->
<?php endforeach;?>
<?= $this->results ?>

然后放置一个pagination.phtml示例,您可以在zend手册中找到它 -lo