Zen Cart Logo
Forums / General Questions / New server re-install - Invalid argument supplied for foreach() error

New server re-install - Invalid argument supplied for foreach() error

Locked

Views: 724

Results 1 to 2 of 2
This thread is locked. New replies are disabled.
13 Mar 2009, 7:19 PM
#1
warstormer avatar

warstormer

Zen Follower

Join Date:
Aug 2007
Posts:
120
Plugin Contributions:
0

New server re-install - Invalid argument supplied for foreach() error

Hi,

Our site has had a lot of modifications so this may not even be zen-cart related but here goes...

I moved a copy of our live site onto a demo server and it works fine, all the files and database are up to date, and all cache files. I have also run the Fix Cache Key. However there are points on the home page where we are getting variations of:

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\fpi_new\includes\templates\fpi\templates\tpl_modules_bestsellers.php on line 11

Line 11 in this case references:

line 8 - include(DIR_WS_MODULES . zen_get_module_directory('bestsellers.php'));
line 9 - // Query results are in $records array
line 10 - //foreach ($records as $id=>$row) {
line 11 - $i = 0; foreach ($records as $id=>$row) { $i++;

bestsellers.php (in our custom template folder) contains the following:

<?php switch (true) { case (SHOW_CURRENT_BEST_SELLERS_LIMIT == '0'): $display_limit = ''; break; case (SHOW_CURRENT_BEST_SELLERS_LIMIT == '1'): $display_limit = " and date_format(o.date_purchased, '%Y%m') >= date_format(now(), '%Y%m')"; break; case (SHOW_CURRENT_BEST_SELLERS_LIMIT == '30'): $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(o.date_purchased) <= 30'; break; case (SHOW_CURRENT_BEST_SELLERS_LIMIT == '60'): $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(o.date_purchased) <= 60'; break; case (SHOW_CURRENT_BEST_SELLERS_LIMIT == '90'): $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(o.date_purchased) <= 90'; break; case (SHOW_CURRENT_BEST_SELLERS_LIMIT == '120'): $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(o.date_purchased) <= 120'; break; } $file = DIR_FS_SQL_CACHE . '/sql_bestseller_cache.txt'; $expire = 84600; // 24 hours if (file_exists($file) && filemtime($file) > (time() - $expire)) { $records = unserialize(file_get_contents($file)); } else { $query = "SELECT DISTINCT op.products_id, pd.products_name, pd.products_description, p.products_image, sum(op.products_quantity) as total FROM orders_products op, orders o, products p, products_description pd WHERE p.products_id = op.products_id AND pd.products_id = op.products_id AND o.orders_id = op.orders_id AND p.products_status = '1' AND o.date_purchased BETWEEN NOW() - INTERVAL 21 DAY AND NOW() GROUP BY op.products_id ORDER BY total DESC LIMIT 5"; $data = mysql_query($query); $rows = 0; while ($record = mysql_fetch_array($data) ) { $rows++; $records[] = $record; } $OUTPUT = serialize($records); $fp = fopen($file,"w"); fputs($fp, $OUTPUT); fclose($fp); } // end else -------------------------- With an updated cache and database (from today), I just can't figure out where the problem is. Any suggestions at all would be really appreciated....
13 Mar 2009, 7:35 PM
#2
warstormer avatar

warstormer

Zen Follower

Join Date:
Aug 2007
Posts:
120
Plugin Contributions:
0

Re: New server re-install - Invalid argument supplied for foreach() error

Solved it.... seems that the entire .txt cache files had to be deleted to 're-boot' the cache... works fine now...