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

  • Home
  • SEARCH
  • 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 6120237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:38:44+00:00 2026-05-23T15:38:44+00:00

Using the Kohana query builder, is it possible to build my query piece by

  • 0

Using the Kohana query builder, is it possible to build my query piece by piece.

Then execute a count on said query.

Then execute the query itself.

All without having to write duplicate conditionals… one for the count and one for the results…

Adding

DB::select(array('COUNT("pid")', 'mycount'))

To the main query results in only getting back one record.

Is it maybe possible to execute the count, and somehow remove

array('COUNT("pid")', 'mycount')

from the select…

Right now the only way I can think of is a find and replace on the SQL code itself, and then just running said code SQL… there must be a better way though… I hope…

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-05-23T15:38:45+00:00Added an answer on May 23, 2026 at 3:38 pm

    To do just that I use 3 methods. First one returns the paginated results, second one gets the count. Third, private method, holds common conditions used by #1 and #2. If the query needs to use JOINs or WHEREs or anything like that, it all goes to #3. This way there is no need to repeat the query.

    /* 1 */
    public function get_stuff($pagination = false){
        $query = DB::select(/* ... columns here ... */);
        $query = $this->get_stuff_query($query);
        if($pagination) $query->limit($pagination->items_per_page)->offset($pagination->offset);
        return $query->execute();
    }
    
    /* 2 */
    public function get_stuff_count(){
        $query = DB::select(array('COUNT("id")', 'total_rows'));
        $query = $this->get_stuff_query($query);
        $result = $query->execute();
        return $result->get('total_rows',0);
    }
    
    /* 3 */
    private function get_stuff_query($query){
        $query->from(/* tablename */);
        $query->join(/* ... */);
        $query->where(/* ... */);
        return $query;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a UNION query using Kohana's query builder . Everything works
I'm using the join_table function with Kohana's ORM to build a query. The following
I'm using Kohana 2.3.2 Most, if not all, of the links on my site
$x=array('a','b','c'); echo form::dropdown('test', $x, 'b'); I'm using the Kohana form helper to build forms,
I am developing a site using kohana 2.3 and am having trouble with a
I'm not even sure if this is possible. I am using Kohana framework(ver 2.3).
I just started to using the Kohana framework and I'm trying to execute a
I'm using Kohana 3. I'm writing an update query, and it is working for
In a Kohana query, I need to retrieve only one element having the same
I want to build a search with four search terms. I'm using Kohana 3.0.7

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.