2 Replies Latest reply on Oct 19, 2010 1:56 AM by jdldn

    Put li tags around every 2 results?

    jdldn Level 1

      I have a system printing out items in a list with this;

      return "<li$item</li>";

       

      How can I modify the code so 2 items are in each li tag?

      Thanks

        • 1. Re: Put li tags around every 2 results?
          w1n78

          to me your title is asking one thing and your question is something different

           

          "Put lli tags around every 2 results?"

          if you have a loop you can use a counter inside the loop with a conditional statement. example...

           

          <?php

          $counter = 0;

          for ($i=0; $i<10; $i++) {

            if ($counter < 1) {

              echo $item;

              $counter++;

            }else{

              echo '<li>'.$item.'</li>';

              $counter = 0;

            }

          }

          ?>

           

          the loop starts at 0 and continues until 10. counter variable has an initial value of 0. if counter variable is less than 1, increment it by 1 and display $item, else reset counter to 0 and display $item between the <li> tags, meaning it looped 2x already.

           

           

           

           

          "2 items in each li tag" do you mean 2 variables? you need to use a period to concatenate between variables

          <?php

          return "<li>".$item.$item2."</li>";

          ?>

          • 2. Re: Put li tags around every 2 results?
            jdldn Level 1

            Thanks