[英]Zend_db & Zend_paginator - Not having a fun time
我遇到了一個嚴重的問題,即將我的“ 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");
為什么在order by子句中有“ <”?
這與Zend_Paginator有什么關系? 啊,您是否有查詢,並且您不知道如何使用它進行分頁,或者分頁器無法與此查詢一起使用?
我唯一能看到的是,您在where()
和order()
子句中都缺少左括號:
$select->where("((69.1 * [...] ");
$select->order("((69.1 * [...] ");
^
那么也許Zend_Paginator不能正常工作,因為SQL查詢有錯誤嗎?
當然,我不得不問:您插值的那些變量是安全的,還是真的應該使用$db->quote($user->latitude, Zend_Db::FLOAT_TYPE)
?
假設您使用的是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 manual -Lo上
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.