Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8911159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:52:10+00:00 2026-06-15T03:52:10+00:00

I have 10 subscriber tables from subscriber_0 to subscriber_9, I get all the data

  • 0

I have 10 subscriber tables from subscriber_0 to subscriber_9, I get all the data from them through union by custom query in subscriber model, in the function getAllSubscribers, this table executes the query and returns the result to the subscriber controller, I have set $useTable = false because there is no subscriber table, my question is how do I paginate this data in the controller?

For reference I am writing my query here and the result returned
Query:

 $query = 'SELECT * FROM (
            SELECT * FROM subscriber_1
            UNION 
            SELECT * FROM subscriber_2
            UNION 
            SELECT * FROM subscriber_3
            UNION 
            SELECT * FROM subscriber_4
            UNION 
            SELECT * FROM subscriber_5
            UNION 
            SELECT * FROM subscriber_6
            UNION 
            SELECT * FROM subscriber_7
            UNION 
            SELECT * FROM subscriber_8
            UNION 
            SELECT * FROM subscriber_9
            UNION 
            SELECT * FROM subscriber_0
            ) AS subscriber WHERE created > \'' . $startDate . '\' AND created < \'' . $endDate . '\'';

Result:

array(
(int) 0 => array(
    'subscriber' => array(
        'a_party' => '923003210861',
        'subtype' => '0',
        'stat' => '0',
        'created' => '2012-11-26 06:53:31',
        'updated' => null
    )
),
(int) 1 => array(
    'subscriber' => array(
        'a_party' => '923005264511',
        'subtype' => '0',
        'stat' => '0',
        'created' => '2012-11-26 06:53:31',
        'updated' => null
    )
)
,
.
.
.
.(int) 50 => ...

I have added this in the subscribers controller

    public $paginate = array(
    'limit' => 10
);

What else do I need to add?

I have seen this but of no help

CakePHP pass custom query from controller into model paginate()

EDIT: Adding controller code below

            $data = $this->Subscriber->getAllSubscribers();//This model method returns custom data from query
        $this->paginate = array('fields' => $selectedField);
        $paginatedData = $this->paginate($data);
        //debug($paginatedData);

        $this->set('subslist', $paginatedData);

The above code is not working, what am i doing wrong, thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:52:11+00:00Added an answer on June 15, 2026 at 3:52 am

    Here is how I achieved it:
    Model code

    /**
     * Overridden paginate method - group by week, away_team_id and home_team_id
     */
    public function paginate($conditions, 
        $fields, 
        $order, 
        $limit, 
        $page = 1, 
        $recursive = null, 
        $extra = array()) {
    
        $recursive = -1;
        $sql = "SELECT * FROM (
            SELECT * FROM blacklist_0
            UNION
            SELECT * FROM blacklist_1
            UNION 
            SELECT * FROM blacklist_2
            UNION 
            SELECT * FROM blacklist_3
            UNION 
            SELECT * FROM blacklist_4
            UNION 
            SELECT * FROM blacklist_5
            UNION 
            SELECT * FROM blacklist_6
            UNION 
            SELECT * FROM blacklist_7
            UNION 
            SELECT * FROM blacklist_8
            UNION 
            SELECT * FROM blacklist_9
            UNION 
            SELECT * FROM blacklist_0
        ) AS Blacklist LIMIT " . (($page - 1) * $limit) . ', ' . $limit;
    
        $results = $this->query($sql);
        return $results;
    }
    
    /**
     * Overridden paginateCount method
     */
    public function paginateCount($conditions = null, 
        $recursive = 0, 
        $extra = array()) {
    
        $sql = "SELECT * FROM (
            SELECT * FROM blacklist_1
            UNION 
            SELECT * FROM blacklist_2
            UNION 
            SELECT * FROM blacklist_3
            UNION 
            SELECT * FROM blacklist_4
            UNION 
            SELECT * FROM blacklist_5
            UNION 
            SELECT * FROM blacklist_6
            UNION 
            SELECT * FROM blacklist_7
            UNION 
            SELECT * FROM blacklist_8
            UNION 
            SELECT * FROM blacklist_9
            UNION 
            SELECT * FROM blacklist_0
        ) AS Blacklist";
    
        if ($conditions['Blacklist.b_party'] <> null) {
            $sql = $sql . ' WHERE Blacklist.b_party = \'' . $conditions['Blacklist.b_party'] . '\'';
        } else if ($conditions['Blacklist.a_party'] <> null) {
            $sql = $sql . ' WHERE Blacklist.a_party = \'' . $conditions['Blacklist.a_party'] . '\'';
        }
    
        $this->recursive = $recursive;
        $results = $this->query($sql);
    
        return count($results);
    }
    

    Not to forget i used

    public $useTable = false;
    

    in the model, but the key thing was how to override the methods, which i finally figured out with the help of my collegue, the controller code is simple. Here it is:
    Controller code:

    public function index() {
        $this->set('msisdn', "");
        $this->Blacklist->recursive = 0;
        $this->set('blacklists', $this->paginate());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to make a view that shows unrelated data from multiple tables. I
I have custom event that has several different subscribers who will all use the
I just changed from Access to mySQL. I have a few tables, called Veranstaltung
I have the following query: SELECT * FROM my_users as U RIGHT JOIN subscribers
The php code below get's the results from a form and inserts them into
Given my two db tables aliases and subscriber have entries like this: aliases.username =
I have two mysql tables and i want to do a select query: My
I have 2 tables namely subscriber and contact. Tables look something like this: subscriber
I have the following query which allows me to join two tables by row
I have 2 tables: users and subscribers . The relationship of the user to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.