1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Automatic change word item to items based on qty in cart?

Discussion in 'PHP' started by FlexiHost, Jun 23, 2010.

  1. #1
    I have the following in my mini cart:

    
    <div class="items"><span class="num">{{{**ITEM**}}}</span> Items in the Cart</div>
    
    Code (markup):
    I used to use in OSCommerce a part which would change the wording - this code is below:
    
    <?php
    $cart_item_count = $cart->count_contents();
    if($cart_item_count == 1) {
      $itemdesc = 'Item';
    } else {
      $itemdesc = 'Items';
    };?>
    
    Code (markup):
    How can I get this to work with my current code? The part {{{**ITEM**}}} will display numbers correctly, like 0,1,2,3 etc - so I thought somehow I could use that as the base, if item <2 show Item if >1 show items

    Thoughts please.
     
    FlexiHost, Jun 23, 2010 IP
  2. flexdex

    flexdex Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You may could use this if the template allows execution of php code
    
    <div class="items"><span class="num">{{{**ITEM**}}}</span> Item<?php echo intval('{{{**ITEM**}}}')>1?'s':''?> in the Cart</div>
    
    PHP:
    or if your script is somehow dumb

    
    <?php $nItems = intval('{{{**ITEM**}}}');?>
    <div class="items"><span class="num"><?php echo $nItems?></span> Item<?php echo $nItems>1?'s':''?> in the Cart</div>
    
    PHP:
    If that fails, just use javascript on a similar way.
     
    flexdex, Jun 24, 2010 IP
  3. clox.c

    clox.c Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <div>Item<?php echo {{{*ITEM*}}} ? 's': ''; ?></div>
    PHP:
     
    clox.c, Jun 24, 2010 IP