0

我在将我的“选择”语句转换为可以与 zend 分页器一起使用的东西时遇到了一个严重的问题......有人可以破解它,因为我没有运气......

这是我的查询:

$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");
4

3 回答 3

1

这与 Zend_Paginator 有什么关系?啊,你有查询,但你不知道如何用它制作分页器,或者分页器不能处理这个查询?

我唯一能看到的是你在where()andorder()子句中都缺少一个左括号:

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

所以也许 Zend_Paginator 不工作是因为 SQL 查询有错误?

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

于 2009-06-11T20:10:45.450 回答
1

为什么您的 order by 子句中有“<”?

于 2009-06-11T19:41:09.453 回答
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 上找到该示例

于 2009-06-11T20:15:42.630 回答