Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Jan 2015
    Posts
    423
    Plugin Contributions
    0

    Default functions_categories.php PHP Warning: sizeof(): Parameter must be an array

    Zen Cart 156

    well i am just about complete with my upgrade. I did find one error that came up... If someone could assist me or lead me in the right direction.\


    PHP Warning: sizeof(): Parameter must be an array or an object that implements Countable in
    C:\xampp\htdocs\xxxxxx.com\includes\functions\functions_categories.php on line 162.

    This is what is on line 162

    Code:
    $subcategories_array[sizeof($subcategories_array)] = $subcategories->fields['categories_id'];

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: functions_categories.php PHP Warning: sizeof(): Parameter must be an array

    What's the rest of the error message stack? (ie: all the other involved files and their line numbers)
    .

    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
    Jan 2015
    Posts
    423
    Plugin Contributions
    0

    Default Re: functions_categories.php PHP Warning: sizeof(): Parameter must be an array

    sorry about that

    Code:
    
    [20-Dec-2018 04:56:45 Europe/Berlin] Request URI: /xxxxxx.com/index.php?main_page=index&cPath=715, IP address: 127.0.0.1
    #1  sizeof() called at [C:\xampp\htdocs\xxxxxx.com\includes\functions\functions_categories.php:162]
    #2  zen_get_subcategories() called at [C:\xampp\htdocs\xxxxxx.com\includes\functions\extra_functions\functions_auto_category_images.php:12]
    #3  auto_category_images() called at [C:\xampp\htdocs\xxxxxx.com\includes\modules\theme871\category_row.php:161]
    #4  require(C:\xampp\htdocs\xxxxxx.com\includes\modules\theme871\category_row.php) called at [C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\templates\tpl_modules_category_row.php:27]
    #5  require(C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\templates\tpl_modules_category_row.php) called at [C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\templates\tpl_index_categories.php:271]
    #6  require(C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\templates\tpl_index_categories.php) called at [C:\xampp\htdocs\xxxxxx.com\includes\modules\pages\index\main_template_vars.php:232]
    #7  require(C:\xampp\htdocs\xxxxxx.com\includes\modules\pages\index\main_template_vars.php) called at [C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\common\tpl_main_page.php:486]
    #8  require(C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\common\tpl_main_page.php) called at [C:\xampp\htdocs\xxxxxx.com\index.php:97]
    [20-Dec-2018 04:56:45 Europe/Berlin] PHP Warning:  sizeof(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\xxxxxx.com\includes\functions\functions_categories.php on line 162

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: functions_categories.php PHP Warning: sizeof(): Parameter must be an array

    I'm guessing your custom code in \includes\functions\extra_functions\functions_auto_category_images.php is not properly set up for calling the zen_get_subcategories() function. It needs to pass an already-initialized array as the first parameter, but in your case it isn't.
    .

    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.

  5. #5
    Join Date
    Jan 2015
    Posts
    423
    Plugin Contributions
    0

    Default Re: functions_categories.php PHP Warning: sizeof(): Parameter must be an array

    yes this is a custom piece of code to get automtatic category images
    https://www.zen-cart.com/downloads.php?do=file&id=1977


    I believe the issue is come from

    zen_get_subcategories( $sub_categories, $catID );
    $image = auto_category_images( $sub_categories[array_rand( $sub_categories )] );

    Code:
    <?php
    
    	function auto_category_images( $catID ) {
    		global $db;
    
    		if ( $catID > 0 ) {
    
    			$cat_has_products = $db->Execute("SELECT p.products_image FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c WHERE p.products_id = p2c.products_id AND p2c.categories_id = " . $catID . " ORDER BY RAND() LIMIT 1");
    		    if($cat_has_products->RecordCount() > 0){
    		    	$image = $cat_has_products->fields['products_image'];
    		    } else {
    		    	zen_get_subcategories( $sub_categories, $catID );
    		    	$image = auto_category_images( $sub_categories[array_rand( $sub_categories )] );
    		  	}
    		} else {
    			// This category contains no products!
    			$image = 'pixel_trans.gif';
    		}
    
    		return $image;
    	}
    
    ?>
    Last edited by chadlly2003; 21 Dec 2018 at 04:03 AM.

  6. #6
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default Re: functions_categories.php PHP Warning: sizeof(): Parameter must be an array

    Change
    Code:
    zen_get_subcategories( $sub_categories, $catID );
    $image = auto_category_images( $sub_categories[array_rand( $sub_categories )] );
    to
    Code:
    zen_get_subcategories( $sub_categories, $catID );
    if (!empty($sub_categories)) { 
       $image = auto_category_images( $sub_categories[array_rand( $sub_categories )] );
    } else {
       $image = 'pixel_trans.gif';
    }
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  7. #7
    Join Date
    Jan 2015
    Posts
    423
    Plugin Contributions
    0

    Default Re: functions_categories.php PHP Warning: sizeof(): Parameter must be an array

    I tried the changes you gave me but for some reason I still getting the same error


    Code:
    [21-Dec-2018 16:54:53 Europe/Berlin] Request URI: /xxxxxx.com/index.php?main_page=index&cPath=715, IP address: ::1
    
    #1  sizeof() called at [C:\xampp\htdocs\xxxxxx.com\includes\functions\functions_categories.php:162]
    
    
    #2  zen_get_subcategories() called at [C:\xampp\htdocs\xxxxxx.com\includes\functions\extra_functions\functions_auto_category_images.php:12]
    
    
    #3  auto_category_images() called at [C:\xampp\htdocs\xxxxxx.com\includes\modules\theme871\category_row.php:161]
    
    
    #4  require(C:\xampp\htdocs\xxxxxx.com\includes\modules\theme871\category_row.php) called at [C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\templates\tpl_modules_category_row.php:27]
    
    
    
    #5  require(C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\templates\tpl_modules_category_row.php) called at [C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\templates\tpl_index_categories.php:271]
    
    
    
    #6  require(C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\templates\tpl_index_categories.php) called at [C:\xampp\htdocs\xxxxxx.com\includes\modules\pages\index\main_template_vars.php:232]
    
    
    
    #7  require(C:\xampp\htdocs\xxxxxx.com\includes\modules\pages\index\main_template_vars.php) called at [C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\common\tpl_main_page.php:486]
    
    
    
    #8  require(C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\common\tpl_main_page.php) called at [C:\xampp\htdocs\xxxxxx.com\index.php:97]
    [21-Dec-2018 16:54:53 Europe/Berlin] PHP Warning:  sizeof(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\xxxxxx.com\includes\functions\functions_categories.php on line 162
    eme871\category_row.php) called at [C:\xampp\htdocs\xxxxxx.com\includes\templates\theme871\templates\tpl_modules_category_row.php:27]

  8. #8
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default Re: functions_categories.php PHP Warning: sizeof(): Parameter must be an array

    You also have to make the change that Dr. Byte mentioned. At the top of your function do

    $sub_categories = array();
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  9. #9
    Join Date
    Jan 2015
    Posts
    423
    Plugin Contributions
    0

    Default Re: functions_categories.php PHP Warning: sizeof(): Parameter must be an array

    this is what the change look. I believe there is an error in the code i just don't know how to fix it.

    Code:
    <?php
    
    	function auto_category_images( $catID ) {
    		global $db;
    
    		if ( $catID > 0 ) {
    
    			$cat_has_products = $db->Execute("SELECT p.products_image FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c WHERE p.products_id = p2c.products_id AND p2c.categories_id = " . $catID . " ORDER BY RAND() LIMIT 1");
    		    if($cat_has_products->RecordCount() > 0){
    		    	$image = $cat_has_products->fields['products_image'];
    		    } else {
    		    	zen_get_subcategories( $sub_categories, $catID );
    if (!empty($sub_categories)) { 
       $image = auto_category_images( $sub_categories[array_rand( $sub_categories )] );
    } else {
       $image = 'pixel_trans.gif';
    }
    		  	}
    		
    		}
    
    		return $image;
    	}
    
    ?>
    Last edited by chadlly2003; 21 Dec 2018 at 05:19 PM.

  10. #10
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default Re: functions_categories.php PHP Warning: sizeof(): Parameter must be an array

    Under global $db; add

    $sub_categories = array();
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 7
    Last Post: 16 Dec 2018, 04:00 PM
  2. v154 PHP Warning: extract() expects parameter 1 to be array
    By JoeH in forum General Questions
    Replies: 2
    Last Post: 15 May 2018, 06:44 PM
  3. PHP Warning: addslashes() expects parameter 1 to be string, array given
    By schoolboy in forum All Other Contributions/Addons
    Replies: 11
    Last Post: 10 May 2013, 02:19 PM
  4. v139e PHP Warning: strlen() expects parameter 1 to be string, array given in
    By irishshopper in forum Basic Configuration
    Replies: 4
    Last Post: 7 Mar 2013, 08:06 PM
  5. Replies: 13
    Last Post: 5 May 2011, 03:48 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