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 4100246
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:32:30+00:00 2026-05-20T20:32:30+00:00

This is my simple query in mysql/zend: // Get Patients $table = new Model_Patient_DbTable();

  • 0

This is my simple query in mysql/zend:

// Get Patients
$table = new Model_Patient_DbTable();
$select = $table->select();
$select->from( 'patient' );
$select->setIntegrityCheck( false );

// insurance join                                                               
$select->joinLeft( 'insurance', 'patient.insuranceId=insurance.Id', 
                                 array( 'insName' => 'insName'));

// Get total no of records
$totalRecords = count( $table->fetchAll( $select ) );

// Filters 
if( $inactive ) {
   $select->where('patient.inactive = ?', $inactive );
}
// Other where clause conditions

// Fetch filtered patient records        
$patientRecords = $table->fetchAll( $select );

// Get total no of filtered patient records 
$filteredRecords = count( $table->fetchAll( $select ) );

In above zend query I am get getting patient records and their insurances based on some conditions in where clause. I have to get (1) Total No. of Records, (2) Total No. of filtered Records and also (3) Patient Records to show on webpage.

Problem is that in my above query I have to fetch records 3 times which slow the performance when there are 10,000 records. How can I optimize my query that it fetch the the records only once OR there should be a separate query for counting that will only get total No of records instead of fetching all records.

Every reply will be appreciated.

Thanks
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-20T20:32:31+00:00Added an answer on May 20, 2026 at 8:32 pm

    Something like this should get you started, unfortunately I don’t have a way of testing this currently.

    // Get Patients
    $table = new Model_Patient_DbTable();
    
    // Get Total records
    $select = $table->select();
    $select->from($table, array('COUNT(*) as row_count'));
    $select->setIntegrityCheck(false);
    $select->joinLeft('insurance', 'patient.insuranceId = insurance.Id', array('insName' => 'insName'));
    $result = $table->fetchAll($select);
    $totalRecords = $result[0]->row_count;
    
    // Filters
    if ($inactive) {
        $select->where('patient.inactive = ?', $inactive);
    }
    
    // Get Total filtered records
    $result = $table->fetchAll($select);
    $filteredRecords = $result[0]->row_count;
    
    // Get filtered records
    $select = $table->select();
    $select->from($table);
    $select->setIntegrityCheck(false);
    $select->joinLeft('insurance', 'patient.insuranceId = insurance.Id', array('insName' => 'insName'));
    if ($inactive) {
        $select->where('patient.inactive = ?', $inactive);
    }
    $patientRecords = $table->fetchAll($select);
    

    Note: You may be able to re-use the same Zend_Db_Select object by overwriting the $select->from() to remove the COUNT(*) addition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to execute this simple mysql query in Zend; UPDATE `table` SET `field`='field'+1
Is there a faster way to perform this most simple query in terms of
I am using Zend_Db with the Pdo_Mysql driver. This query does not give any
I have a mysql database with a particular table with a little over 6
I have a table with id column. id s are in ascending order but
When running the follow query i receive the error below, Im just trying to
I have MySQL with below settings Server version: 5.0.77 MySQL client version: 5.0.41 Protocol
Sample code: $email = . $_POST['email']; $con = mysql_connect(localhost,user,pass) or die('Could not connect to
It must be Monday, the heat or me being stupid (prob the latter), but
I want to make my own function which performs in a similar manner 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.