WordPress.org

Ready to get started?Download WordPress

Forums

Troubleshoot $wpdb queries (2 posts)

  1. FPG
    Member
    Posted 1 year ago #

    Hello All,

    I semi inherited a report generator that pulls a bunch of information from various tables into the database with one big query and I'm running into issues when the query returns large data sets.

    I have a statement like so:

    $ui = $wpdb->get_results($q);

    When I count($ui), I can see that there are 5261 records in the dataset which is correct. When I try to print out all these records with a foreach loop...

    foreach($ui as $usr){
      echo $usr->id;
      set_time_limit(0);
    }

    My foreach loop suddenly stops at record 3515 of the query and kills the rest of the script. I have the set_time_limit to tell PHP to keep going.

    I'm no MySQL wizard, but it looks like the database is closing the connection prematurely. I'm not getting any PHP errors, just a blank white screen.

    Any ideas?

    Thanks!

  2. vtxyzzy
    Member
    Posted 1 year ago #

    You can probably add pagination to the array to solve the problem. Here is an article with sample code that shows how to use paginate_links() to paginate an array: http://wordpress.mcdspot.com/2010/11/25/pagination-using-paginate_links/

Topic Closed

This topic has been closed to new replies.

About this Topic