♥Monika in Germany Posted September 3, 2005 Share Posted September 3, 2005 Hi, right at the spot where I ended this code snippet, I have to loop once more through the complete cart to get a special value for a mod. I have done so successfully by adding a reset and calling the list again, but obviously that did not store the spot where I left and my first while loop ended right after the one and only product called ... and I have 12 products in my test cart. Is there a different way to access a cart loop, so I could call that one for the inner loop while the outer would stay intact? Or is there a way to mark where I left the loop and return to the same spot after the inner loop so I can continue to work down my list of cart items, instead of only getting the first one? The first part of the get_products function isn't changed, the later part either, I just have to have that other peive of code in between. Bummer. thanks in advance for help, I'm quite stuck here :-) function get_products() { global $languages_id; if (!is_array($this->contents)) return false; $products_array = array(); reset($this->contents); while (list($products_id, ) = each($this->contents)) { $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'"); if ($products = tep_db_fetch_array($products_query)) { $prid = $products['products_id']; $products_price = $products['products_price']; :-) Monika addicted to writing code ... can't get enough of databases either, LOL! my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum Interactive Media Award July 2007 ~ category E-Commerce my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ... Link to comment Share on other sites More sharing options...
Daemonj Posted September 3, 2005 Share Posted September 3, 2005 Change the while loop to a for loop. When you return from your inner or second loop, you should remain in place as the counter will not have changed. "Great spirits have always found violent opposition from mediocre minds. The latter cannot understand it when a man does not thoughtlessly submit to hereditary prejudices but honestly and courageously uses his intelligence." - A. Einstein Link to comment Share on other sites More sharing options...
♥Monika in Germany Posted September 3, 2005 Author Share Posted September 3, 2005 Change the while loop to a for loop. When you return from your inner or second loop, you should remain in place as the counter will not have changed. <{POST_SNAPBACK}> that sounds like a fabulous idea ... so I changed while (list($products_id, ) = each($this->contents)) { to for($i=0, $n=sizeof($this->contents); $i<$n; $i++) { $products_id = $this->contents[$products_id]; $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'"); which was obviously not a good idea and has a mistake, as it does not fill my $products_id ... would you mind telling me how to do it correctly? :-) Monika addicted to writing code ... can't get enough of databases either, LOL! my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum Interactive Media Award July 2007 ~ category E-Commerce my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ... Link to comment Share on other sites More sharing options...
♥Monika in Germany Posted September 3, 2005 Author Share Posted September 3, 2005 with this I do not even get one result line .... // reset($this->contents); // while (list($products_id, ) = each($this->contents)) { foreach ($this->contents as $products_id) { $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'"); :-) Monika addicted to writing code ... can't get enough of databases either, LOL! my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum Interactive Media Award July 2007 ~ category E-Commerce my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ... Link to comment Share on other sites More sharing options...
Guest Posted September 3, 2005 Share Posted September 3, 2005 hello Monika, you need the reset I think this rewinds the array ptr to the beginning of the array Link to comment Share on other sites More sharing options...
boxtel Posted September 4, 2005 Share Posted September 4, 2005 that sounds like a fabulous idea ...so I changed ? ? ?while (list($products_id, ) = each($this->contents)) { to ? ? ?for($i=0, $n=sizeof($this->contents); $i<$n; $i++) { ? ? ? $products_id = $this->contents[$products_id]; ? ? ? ?$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'"); which was obviously not a good idea and has a mistake, as it does not fill my $products_id ... would you mind telling me how to do it correctly? <{POST_SNAPBACK}> products_id is the key to that array which makes for looping virtually impossible. On the other hand, nested for loops would be ideal for your purpose. In that light I would first create a sequential indexed array with the products_id's and use that array in the for loops. Treasurer MFC Link to comment Share on other sites More sharing options...
Daemonj Posted September 4, 2005 Share Posted September 4, 2005 Change while (list($products_id, ) = each($this->contents)) { to be: $keyArray = array_keys($this->contents); for ($i=0, $n=sizeof($keyArray); $i<$n; $i++) { $products_id = $keyArray[$i]; and that should do it for you. ;) "Great spirits have always found violent opposition from mediocre minds. The latter cannot understand it when a man does not thoughtlessly submit to hereditary prejudices but honestly and courageously uses his intelligence." - A. Einstein Link to comment Share on other sites More sharing options...
♥Monika in Germany Posted September 4, 2005 Author Share Posted September 4, 2005 thanks so much e/o :-) .... this worked like a treat. As I have been known to create endless loops 6 years ago, I was pretty surprised when my new loops only had one item or zero hehe ... but at least I knew why, even if I did not know how to resolve it. Your solution was fab, just what I needed. :-) Monika addicted to writing code ... can't get enough of databases either, LOL! my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum Interactive Media Award July 2007 ~ category E-Commerce my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.