Zend_db & Zend_paginator - 没有玩得很开心

发布于 2024-07-23 12:46:06 字数 2319 浏览 9 评论 0原文

我在将“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");

I am having a serious problem converting my 'select' statement into something that will work with the zend paginator... could someone have a crack at it, as I am having no luck...

Here is my query:

$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))

Here is what I have so far:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不甘平庸 2024-07-30 12:46:06

这和 Zend_Paginator 有什么关系? 啊,您是否有查询但不知道如何用它制作分页器,或者分页器不适用于此查询?

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

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

所以也许 Zend_Paginator 不起作用,因为 SQL查询有错误?

当然,我必须问:您插入的那些变量是否安全,或者您真的应该使用 $db->quote($user->latitude, Zend_Db::FLOAT_TYPE) 吗?

What does this have to do with Zend_Paginator? Ah, do you have the query and you don't know how to make a paginator with it, or is the paginator not working with this query?

The only thing I can see is you're missing an opening parenthesis in both the where() and order() clause:

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

So maybe Zend_Paginator isn't working because the SQL query has errors?

And of course I have to ask: are those variables you're interpolating safe, or should you really be using $db->quote($user->latitude, Zend_Db::FLOAT_TYPE)?

动听の歌 2024-07-30 12:46:06

假设您使用 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 手册上找到该示例
-洛

Assuming you are using MVC-pattern, won't this work?

in your bootstrap:

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

in your controller:

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

in your view:

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

then place a pagination.phtml example that you can find on zend manual
-Lo

澜川若宁 2024-07-30 12:46:06

为什么有“<” 在你的 order by 条款中?

Why do you have "<" in your order by clause?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文