Announcement

Collapse
No announcement yet.

Incrementing ListIndex via PHP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Incrementing ListIndex via PHP

    I have a layout list which requires each item to be wrapped in a unique id="itemn" ... I can use the ListIndex to create item1, item2, item3 etc and it works fine.

    I am looking for a way to increment the current ListIndex by 1 so as to be able to create a hyperlink to the next item. My non-existent PHP is generating parse errors no matter how many monkeys I let at the keyboard

    There surely has to be a way to increment the current ListIndex by 1 to enable a link to be generated to the next item in the list?

    Jont


    Bikster
    SellerDeck Designs and Responsive Themes

    #2
    maybe a for .... next loop?

    http://www.w3schools.com/php/php_looping.asp
    Last edited by wjcampbe; 03-Nov-2007, 02:27 PM. Reason: add link to w3schools
    Bill
    www.egyptianwonders.co.uk
    Text directoryWorldwide Actinic(TM) shops
    BC Ness Solutions Support services, custom software
    Registered Microsoft™ Partner (ISV)
    VoIP UK: 0131 208 0605
    Located: Alexandria, EGYPT

    Comment


      #3
      Oh blimming heck... my cack handed typing combined with serving customers and not having a real foggiest about PHP... managed to sort it:


      <actinic:block php="true" >
      $list = <actinic:variable name="ListIndex" />;
      $next = $list ++;
      echo "$next" ;
      </actinic:block>

      I can now wrap the code in a condition to see if it is the first or last and miss off accordingly.


      Bikster
      SellerDeck Designs and Responsive Themes

      Comment


        #4
        Or in a 1 liner
        Code:
        <actinic:block php="true">echo (<actinic:variable name="ListIndex" /> + 1);</actinic:block>
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Thanks Norman.

          The echo is not there in the working code.. that was simply to show it was working as desired.. as I am introducing the incremented value into a script in the <a> so reintroducing the ListIndex as the variable ('itemListIndex')

          This is working fine. Now just need to sort how to decrement to also allow a "previous" link .. using "--" and "-1", "-2" etc are having no effect as when clicking on the previous link it takes you to the next link

          Enough for today. Time for home once the server is backed up. A fresh look will no doubt reap dividends.


          Bikster
          SellerDeck Designs and Responsive Themes

          Comment


            #6
            There's another variable ListCount that may be of use to you. This contains the number of items in the list. So (untested)
            Code:
            <actinic:block php="true">
            if ( <actinic:variable name="ListIndex" /> != 1 ) echo "Prevlink code";
            if ( <actinic:variable name="ListIndex" /> < <actinic:variable name="ListCount" /> ) echo "Nextlink code";
            </actinic:block>
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #7
              Just to update the thread.

              The script I was using started the count from 0 so I was able to use the ListIndex to link to the next item in the list.

              The previous item was done via ListIndex - 1. As the PHP output was a javascript link I placed the decrementing code into a layout and called that into the hyperlink with encoding set to quotable perl (I always forget to do this).


              Bikster
              SellerDeck Designs and Responsive Themes

              Comment


                #8
                Just about finished the tweaks .. can be seen at the bottom of http://www.barrelsandbottles.co.uk/ under the "Whats Hot" and uses the best sellers list.

                Thanks Bill and Norman for kicking me in the right direction.


                Bikster
                SellerDeck Designs and Responsive Themes

                Comment

                Working...
                X