Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2008
    Posts
    1,336
    Plugin Contributions
    1

    Default Creating an IF Statement for an array

    I am trying to create an statement to display different banner based on the manufacturer page and categories. It works fine when I put one manufacturer and one cPath but I need an array of cPath not sure how to do that. Here is the statement I used
    PHP Code:
    <div id="siteBanners">
    <?php 
    if ($current_page_base == 'index' and ($manufacturers_id == '36' or $cPath == array('141_160','141_156','141_145','141_157','141_159','141_142','141_149','141_152','141_153','141_150','141_143','144_155','144_154','144_146','144_147','144_151','258_158')) ) {
             echo
    '<a href="/pop-ups/seibon-coupon.html" rel="popup console 500 350 noicon"><img src="'DIR_WS_TEMPLATES $template_dir '/images/banners/seibon-banner.gif" alt="Get 10% off Seibon Products" /></a>'
         } elseif (
    $current_page_base == 'index') {
               echo 
    '<a href="/pop-ups/google-checkout-sale.html" rel="popup console 500 350 noicon"><img src="'DIR_WS_TEMPLATES $template_dir '/images/banners/GoogleCheckout-banner.gif" alt="Get 10% Off Your Order with Google Checkout" /></a>';
        }
    ?>
    </div>
    Note this statement is wrong, I am using only one cPath now but I would love to get the statement working for multiple categories.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,987
    Plugin Contributions
    15

    Default Re: Creating an IF Statement for an array


  3. #3
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Creating an IF Statement for an array

    Adapt fro tpl_main_page.php:[pgp]// the following IF statement can be duplicated/modified as needed to set additional flags
    if (in_array($current_page_base,explode(",",'list_pages_to_skip_all_right_sideboxes _on_here,separated_by_commas,and_no_spaces')) ) {
    $flag_disable_right = true;
    }[/php]

    if (in_array($cPath, ,explode(",",'141_160','141_156','141_145','141_157','141_159','141_142','141_14 9','141_152','141_153','141_150','141_143','144_155','144_154','144_146','144_14 7','144_151','258_158')) ) {
    //your code
    }

  4. #4
    Join Date
    Feb 2008
    Posts
    1,336
    Plugin Contributions
    1

    Default Re: Creating an IF Statement for an array

    You know I looked at that but I didn't know how to really adapt it to my case. I learned Zen Cart by trail and error so sometimes I don't understand the actual php syntax. Thanks for both answers I think I can get it working now.

  5. #5
    Join Date
    Feb 2008
    Posts
    1,336
    Plugin Contributions
    1

    Default Re: Creating an IF Statement for an array

    Hey Glenn
    I used the code from your post and it didn't work....here is my code:
    PHP Code:
    <?php if (in_array($cPath,explode(",",'141_160','141_156','141_145','141_157','141_159','141_142','141_149','141_152','141_153','141_150','141_143','144_155','144_154','144_146','144_147','144_151','258_158')) ) {
        echo
    '<a href="/pop-ups/seibon-coupon.html" rel="popup console 500 350 noicon"><img src="'DIR_WS_TEMPLATES $template_dir '/images/banners/seibon-banner.gif" alt="Get 10% off Seibon Products" /></a>'
         } elseif (
    $current_page_base == 'index') {
        echo 
    '<a href="/pop-ups/google-checkout-sale.html" rel="popup console 500 350 noicon"><img src="'DIR_WS_TEMPLATES $template_dir '/images/banners/GoogleCheckout-banner.gif" alt="Get 10% Off Your Order with Google Checkout" /></a>';
    }
    ?>

  6. #6
    Join Date
    Nov 2003
    Posts
    1,987
    Plugin Contributions
    15

    Default Re: Creating an IF Statement for an array

    There is an error in the use of the explode function.

    You are sending every cPath value as a different parameter to the explode function. But all cPath values should be in a single string, delimited by commas.

    for example like this:
    Code:
    <?php 
    $my_cPath_string = "141_160,141_156,141_145";
    if (in_array($cPath,explode(',', $my_cPath_string)) ) {
       // your code here
    }?>

  7. #7
    Join Date
    Feb 2008
    Posts
    1,336
    Plugin Contributions
    1

    Default Re: Creating an IF Statement for an array

    That worked, thank you.

  8. #8
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Creating an IF Statement for an array

    Right, copied the list of cPaths from the array without converting it to the explode format.

 

 

Similar Threads

  1. Warning: array_merge() [function.array-merge]: Argument #1 is not an array
    By antieuclid in forum PayPal Express Checkout support
    Replies: 3
    Last Post: 19 Jul 2010, 02:50 AM
  2. Replies: 19
    Last Post: 14 Dec 2009, 01:17 PM
  3. Syntax for an IF statement
    By brushwoodnursery in forum General Questions
    Replies: 0
    Last Post: 8 Nov 2008, 09:39 PM
  4. Replies: 1
    Last Post: 14 Mar 2008, 02:58 AM
  5. Replies: 2
    Last Post: 1 Jul 2007, 05:23 AM

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