PHP Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FADE19
    Snow's Parole Officer
    • Sep 2001
    • 1161

    #1

    PHP Question

    Soul...you out there...this is an easy one I think...I just hate loops...

    I would like to print a line...after every 5 lines...

    Example:
    how's life...
    how's life...
    how's life...
    how's life...
    how's life...
    JUST FINE THANKS...
    how's life...
    etc...

    thanks in advance
  • FATPad
    Confirmed User
    • Oct 2001
    • 6693

    #2
    Keep a counter of how many lines you've printed and every time you print a line check the mod result of the counter.

    if ($counter%5=0) {
    echo "This is the line to print every 5th line."
    }

    Basically if the reminder of the counter divided by 5 is 0 you want to print that line. I typed it wrong before and this probably wrong, too, but that's the general concept anyways.

    [This message has been edited by FATPad (edited 01-13-2002).]
    <a href="http://www.adultcontent.co.uk">Adult Content UK - Great British Content</a>

    Comment

    • FATPad
      Confirmed User
      • Oct 2001
      • 6693

      #3
      Holy fucken christ am I an idiot now. I shouldn't be near a keyboard.


      [This message has been edited by FATPad (edited 01-13-2002).]
      <a href="http://www.adultcontent.co.uk">Adult Content UK - Great British Content</a>

      Comment

      • awechen
        Confirmed User
        • Oct 2001
        • 162

        #4
        for ($i=1; $i<20; $i++)
        { echo "some text $i \n ";
        if (!($i % 5)) { echo "line 5"; }
        }

        NOTE u have to start with an 1 not 0 ...




        ------------------
        ah you have been blessed with 72 virgins?
        ah you have been blessed with 72 virgins?

        Comment

        • awechen
          Confirmed User
          • Oct 2001
          • 162

          #5
          works

          awechen@office -- /home/awechen > ./php -q
          ?
          for ($i=1; $i<20; $i++)
          { echo "some text $i \n ";
          if (!($i % 5)) { echo "line 5\n"; }
          }?
          some text 1
          some text 2
          some text 3
          some text 4
          some text 5
          line 5
          some text 6
          some text 7
          some text 8
          some text 9
          some text 10
          line 5
          some text 11
          some text 12
          some text 13
          some text 14
          some text 15
          line 5
          some text 16
          some text 17
          some text 18
          some text 19
          awechen@office -- /home/awechen >


          ------------------
          ah you have been blessed with 72 virgins?

          [This message has been edited by awechen (edited 01-14-2002).]
          ah you have been blessed with 72 virgins?

          Comment

          Working...