Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2012
    Posts
    14,857
    Plugin Contributions
    17

    Default reuse of SQL query results without rerunning query and with minimal memory use

    I am working on a mod to a plugin. Currently results of a query are used to present all of the applicable information on the screen with a summary at the end; however, I would like to be able to provide the summary at the beginning.

    The two methods of this I can conceive are to save the results of the query to a second variable, step through as needed to get the summary, and then use the second variable to resent the information and repeat the results. Ibelieve this would use extra memory unnecessarily.

    The second option I can think of is to run the query, calculate, run the query and display; however, this has the potential of providing two different results. (The second containing more info than the first.)

    Isn't there some type of command to return back to the start of the query result or to capture a pointer to the head and reset the query back to the identified position?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    9,419
    Plugin Contributions
    72

    Default Re: reuse of SQL query results without rerunning query and with minimal memory use

    You can use a code construct similar to:
    Code:
    $result = $db->Execute($your_sql_code);
    while(!$result->EOF) {
      <perform your summary calculations>
      $result->MoveNext();
    }
    $result->Move(0);  // Move to first element ...
    $result->MoveNext();  // Required to not process first element twice
    while(!$result->EOF) {
      <do your line-by-line display>
      $result->MoveNext();
    }
    unset($result);

  3. #3
    Join Date
    Jul 2012
    Posts
    14,857
    Plugin Contributions
    17

    Default Re: reuse of SQL query results without rerunning query and with minimal memory use

    A little unclear on the use of movenext immediately after move(0). Wouldn't I need to enter the second loop with the pointer at the first element? (Assuming that the first element is at position zero.) That way if zero elements are returned then the loop would be bypassed like the first loop would be? Or does position zero point to BOF and there is no info in it and if there were no elements returned that position "1" would be EOF?

    Btw, sorry, THANK YOU for your prompt response and what looks like a functional and simple solution.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    9,419
    Plugin Contributions
    72

    Default Re: reuse of SQL query results without rerunning query and with minimal memory use

    Quote Originally Posted by mc12345678 View Post
    A little unclear on the use of movenext immediately after move(0). Wouldn't I need to enter the second loop with the pointer at the first element? (Assuming that the first element is at position zero.) That way if zero elements are returned then the loop would be bypassed like the first loop would be? Or does position zero point to BOF and there is no info in it and if there were no elements returned that position "1" would be EOF?

    Btw, sorry, THANK YOU for your prompt response and what looks like a functional and simple solution.
    The requirement for the MoveNext() call after the Move(0) call is based on the core code's operation. Essentially, the Move(0) kinda-sorta-not-exactly positions the pointer and the call to MoveNext() finalizes the operation. I'm want to call it a "bug" since there are at least two plugins (one of them mine) that "assume" this behavior.

  5. #5
    Join Date
    Jul 2012
    Posts
    14,857
    Plugin Contributions
    17

    Default Re: reuse of SQL query results without rerunning query and with minimal memory use

    Quote Originally Posted by lat9 View Post
    The requirement for the MoveNext() call after the Move(0) call is based on the core code's operation. Essentially, the Move(0) kinda-sorta-not-exactly positions the pointer and the call to MoveNext() finalizes the operation. I'm want to call it a "bug" since there are at least two plugins (one of them mine) that "assume" this behavior.
    I'm good with that. (Ie haven't actually "arrived" at the beginning until the first movenext after a move(0). ) If that's what php/mySQL needs, then that's what it will get. :) again, thank you.
    Last edited by mc12345678; 17 Oct 2013 at 10:57 PM.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

 

 

Similar Threads

  1. v154 Help with a SQL Query for Query Builder
    By lindasdd in forum Managing Customers and Orders
    Replies: 2
    Last Post: 24 Mar 2016, 01:18 PM
  2. v139h Use of SQL Query Executor
    By GerryTheMole in forum General Questions
    Replies: 5
    Last Post: 26 Mar 2014, 03:07 PM
  3. v151 SQL query setup. How do I TEST a query 'off-line'?
    By lewisasding in forum General Questions
    Replies: 3
    Last Post: 8 Mar 2013, 12:24 AM
  4. Help with a sql query
    By batteryman in forum General Questions
    Replies: 21
    Last Post: 3 Oct 2008, 11:12 PM
  5. Formatting SQL query results
    By haasPlay in forum Contribution-Writing Guidelines
    Replies: 1
    Last Post: 1 Aug 2008, 09:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR