Serial Number Incrementation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Limno
    New Member
    • Apr 2008
    • 92

    Serial Number Incrementation

    Hi all
    Can anyone tell how to increment the serial number, now i m displaying $i value for that, its displaying 1,2,3,4,5. if next set of question again it displaying 1,2,3,4,5

    But i need for 1st set 1,2,3,4,5
    and then 2nd set 6,7,8,9,10.
    like this.
    How can i do this

    Thanks in Advance.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Whatever variable contains the value of your serial number: initialize it outside of the loop, so that it doesn't get reset every loop.

    For example:
    [code=php]<?php
    $serial = 0;
    for($x = 0; $x < 2; ++$x)
    {
    for($y = 0; $y < 5; ++$y)
    {
    ++$serial;
    echo "{$serial}: {$x}x{$y}\n";
    }
    }
    ?>[/code]

    Comment

    Working...