[英]Zend_db & Zend_paginator - Not having a fun time
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");
为什么在order by子句中有“ <”?
What does this have to do with Zend_Paginator? 这与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: 我唯一能看到的是,您在
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)
?
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 manual -Lo上
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.