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()"
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()"
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.
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.
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']; }
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.
How would I go about doing it that way?
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.