Zend_db & Zend_paginator - 没有玩得很开心
我在将“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这和 Zend_Paginator 有什么关系? 啊,您是否有查询但不知道如何用它制作分页器,或者分页器不适用于此查询?
我唯一能看到的是你在
where()
和order()
子句中都缺少一个左括号:所以也许 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()
andorder()
clause: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)
?假设您使用 MVC 模式,这行不通?
在你的引导程序中:
在你的控制器中:
在你的视图中:
然后放置一个 pagination.phtml 示例,您可以在 zend 手册上找到该示例
-洛
Assuming you are using MVC-pattern, won't this work?
in your bootstrap:
in your controller:
in your view:
then place a pagination.phtml example that you can find on zend manual
-Lo
为什么有“<” 在你的 order by 条款中?
Why do you have "<" in your order by clause?