Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2007
    Posts
    120
    Plugin Contributions
    0

    Default 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....

  2. #2
    Join Date
    Aug 2007
    Posts
    120
    Plugin Contributions
    0

    Default 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...

 

 

Similar Threads

  1. v151 Invalid argument supplied for foreach()
    By DML73 in forum General Questions
    Replies: 3
    Last Post: 31 Dec 2013, 04:47 AM
  2. v139g Invalid argument supplied for foreach()
    By rstar23 in forum General Questions
    Replies: 3
    Last Post: 16 Apr 2012, 05:48 AM
  3. Help receiving: Warning: Invalid argument supplied for foreach()
    By kateoeight in forum General Questions
    Replies: 9
    Last Post: 1 May 2007, 09:28 PM
  4. Warning: Invalid argument supplied for foreach
    By harlyman in forum General Questions
    Replies: 9
    Last Post: 23 Aug 2006, 11:39 AM
  5. Replies: 7
    Last Post: 31 Jul 2006, 04:03 AM

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