Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2012
    Posts
    5
    Plugin Contributions
    0

    Default How to reset an object after using MoveNext()?

    Running through a loop on a database object, I use MoveNext() to iterate, but how do I get back to the beginning of the object then? MoveFirst() gives me the error

    "Fatal error: Call to undefined method queryFactoryResult::MoveFirst()"

  2. #2
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: How to reset an object after using MoveNext()?

    There isn't a specific built-in class method for what you're asking for.

    But, I must ask: why are you asking for this? What is it you're doing that requires resetting to iterate through the data again? Is there a better way that you can do it that's not only more efficient but also negates the need for doing a reset?

    At the very least you could create your own array from the resultset just before your MoveNext() calls, and then iterate through that array later if it's actually really necessary.
    Or you could re-query the database using the same Execute() call and end up with another resultset object. Not as efficient that way, but the db engine will have it cached so will return the results very quickly, and if it's something you're only needing to do occasionally on the admin side, and not on every page that your customers visit on the frontend, then the minor performance hit is moot.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Mar 2012
    Posts
    5
    Plugin Contributions
    0

    Default Re: How to reset an object after using MoveNext()?

    I'm comparing data against each other in two tables.

    Basically have two !EOF while loops within each other. I take the first result and compare it against every id in the second table, if it doesn't exist I print it out, if it does I skip it.

    My problem is the 2nd while loop only runs against the first loop once since I use movenext right before the end of the loop so after the first loop through its done with. I did add a database call to refresh it right after the loop which works, but is extremely slow.

  4. #4
    Join Date
    Mar 2012
    Posts
    5
    Plugin Contributions
    0

    Default Re: How to reset an object after using MoveNext()?

    Code:
    while(!$products->EOF){ 
    	$check = NULL;
    		while(!$products2->EOF){ 
    			if($products->fields['products_id'] == $products2->fields['products_id'])
    			{
    				$check = true;
    			}
    		$products2->MoveNext();
    			}
    		  if($check == NULL)
    		  {
    			echo $products->fields['products_id'];
    		  }

  5. #5
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: How to reset an object after using MoveNext()?

    You'd probably find way better performance if you just did it all in one SQL query, instead of nested PHP loops.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    Mar 2012
    Posts
    5
    Plugin Contributions
    0

    Default Re: How to reset an object after using MoveNext()?

    How would I go about doing it that way?

  7. #7
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: How to reset an object after using MoveNext()?

    You wrote a MySQL query to retrieve data, right? So, change that query to include whatever logic that your comparison is trying to do, and then just output the results instead.

    You can find information on writing queries in MySQL at the MySQL website: http://dev.mysql.com/doc/
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. Replies: 5
    Last Post: 31 Jul 2012, 11:33 AM
  2. v139h Fatal error: Call to a member function MoveNext() on a non-object
    By welshop.com in forum General Questions
    Replies: 1
    Last Post: 15 Jul 2012, 03:36 PM
  3. Replies: 4
    Last Post: 23 Jan 2010, 09:35 PM
  4. Replies: 0
    Last Post: 10 Nov 2008, 02:37 PM

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