Search code examples
phpzend-frameworkzend-paginator

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...

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

Solution

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