Ok.. worked on this a bit more and figured out a solution that works
for now. Just need to make it more dynamic and i'll be good to go.
Maybe someone else can find this useful.

in my model:

        function paginate($conditions = null, $fields = null, $order = null,
$limit = null, $page = 1, $recursive = null) {

                /* setup order by variables */
                $orderValues = array_values($order);
                $orderKey = key($order);
                $tmpOrder = explode('.', $orderKey);

                /* setup fields to display on summary */
                $common_fields = 'mlsid, class, class_type, area_id, status,
subdivision, asking_price, agent_name, office_name, address, city,
state, zip, status_id';

                /* for page limiting */
                $pglimit = $page * $limit - ($limit);

        $listings = $this->query("      SELECT $common_fields FROM
ccar_stage.listings_commercial WHERE $conditions UNION ALL
                                                                        SELECT 
$common_fields FROM ccar_stage.listings_land WHERE
$conditions UNION ALL
                                                                        SELECT 
$common_fields FROM ccar_stage.listings_residential
WHERE $conditions UNION ALL
                                                                        SELECT 
$common_fields FROM ccar_stage.listings_multifamily
WHERE $conditions UNION ALL
                                                                        SELECT 
$common_fields FROM ccar_stage.listings_condotownhouse
WHERE $conditions
                                                                        ORDER 
BY $tmpOrder[1] $orderValues[0], asking_price desc
                                                                        LIMIT 
$pglimit, $limit
                                                                ");
                return $listings;

        }

        function paginateCount($conditions = null) {

                $cnt = $this->query("   SELECT COUNT(*) as count FROM
ccar_stage.listings_commercial  WHERE $conditions UNION ALL
                                                                SELECT COUNT(*) 
as count FROM ccar_stage.listings_land WHERE
$conditions UNION ALL
                                                                SELECT COUNT(*) 
as count FROM ccar_stage.listings_residential
WHERE $conditions UNION ALL
                                                                SELECT COUNT(*) 
as count FROM ccar_stage.listings_multifamily
WHERE $conditions UNION ALL
                                                                SELECT COUNT(*) 
as count FROM
ccar_stage.listings_condotownhouse WHERE $conditions
                                                        ");
                $totalCnt = 0;
                foreach($cnt as $key => $value) {
                        $clscnt[$key] = $value[0]['count'];
                        $totalCnt = $totalCnt + $clscnt[$key];
                }
                return $totalCnt;
        }

in controller:

                        $this->paginate['Listing'] = array(
                                                                                
                'conditions' => 'status_id = 0',
                                                                                
                'order' => 'asking_price desc',
                                                                                
                'limit' => 10,
                                                                                
                'page' => 1
                                                                                
          );

                        //$this->Listing->unbindAll(); // unbind all 
associations

                        $this->Listing->paginateCount($this->paginate['Listing']
['conditions']);
                        $listings = $this->paginate();

                        //debug($this->params['paging']);
                        $this->set('listings', $listings);


Now I need to work on assocations... Anyone have any input on how this
looks? Any advice?

Thanks

On Jan 16, 1:26 pm, chad <[EMAIL PROTECTED]> wrote:
> Just wondering if there is an easy way to paginate this query ->
>
> $common_fields = 'mlsid, class, class_type, area_id, status,
> subdivision, asking_price, agent_name, office_name, address, city,
> state, zip';
> $query = mysql_query("     SELECT $common_fields FROM listings_commercial
> UNION ALL
>                                                 SELECT $common_fields FROM 
> listings_land UNION ALL
>                                                 SELECT $common_fields FROM 
> listings_residential UNION ALL
>                                                 SELECT $common_fields FROM 
> listings_multifamily UNION ALL
>                                                 SELECT $common_fields FROM 
> listings_condotownhouse
>                                                 ORDER BY asking_price LIMIT 
> 10");
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to