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...
我遇到了一个严重的问题,将我的'select'语句转换为可以与zend paginator一起工作的东西...有人可以解决它,因为我没有运气...
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");
3 个解决方案
#1
Why do you have "<" in your order by clause?
为什么你的订单中有“<”?
#2
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?
这与Zend_Paginator有什么关系?啊,你有查询,你不知道如何使用它创建一个paginator,或者是不使用此查询的paginator?
The only thing I can see is you're missing an opening parenthesis in both the where()
and order()
clause:
我唯一能看到的是你在where()和order()子句中都缺少一个左括号:
$select->where("((69.1 * [...] ");
$select->order("((69.1 * [...] ");
^
So maybe Zend_Paginator isn't working because the SQL query has errors?
也许Zend_Paginator不工作,因为SQL查询有错误?
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)
?
当然,我不得不问:那些你正在插入安全的变量,或者你真的应该使用$ db-> quote($ user-> latitude,Zend_Db :: FLOAT_TYPE)?
#3
Assuming you are using MVC-pattern, won't this work?
假设您正在使用MVC模式,这不会起作用吗?
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
然后放置一个pagination.phtml示例,您可以在zend手册上找到-Lo
#1
Why do you have "<" in your order by clause?
为什么你的订单中有“<”?
#2
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?
这与Zend_Paginator有什么关系?啊,你有查询,你不知道如何使用它创建一个paginator,或者是不使用此查询的paginator?
The only thing I can see is you're missing an opening parenthesis in both the where()
and order()
clause:
我唯一能看到的是你在where()和order()子句中都缺少一个左括号:
$select->where("((69.1 * [...] ");
$select->order("((69.1 * [...] ");
^
So maybe Zend_Paginator isn't working because the SQL query has errors?
也许Zend_Paginator不工作,因为SQL查询有错误?
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)
?
当然,我不得不问:那些你正在插入安全的变量,或者你真的应该使用$ db-> quote($ user-> latitude,Zend_Db :: FLOAT_TYPE)?
#3
Assuming you are using MVC-pattern, won't this work?
假设您正在使用MVC模式,这不会起作用吗?
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
然后放置一个pagination.phtml示例,您可以在zend手册上找到-Lo