Jump to content


Photo

Increasing numbers/letters


  • Please log in to reply
21 replies to this topic

#21 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 18 September 2006 - 07:18 PM

This should work for any length, any format

<?php
function IncNextPos (&$id, $pos) {
    $min = is_numeric($id{$pos}) ? '1' : 'A';
    $max = is_numeric($id{$pos}) ? '9' : 'Z';
    
    if ($id{$pos}==$max) {
        $id{$pos} = $min;
        IncNextPos($id,$pos-1);
    }
    else {
        $x = $id{$pos};
        $x++;
        $id{$pos} = $x;
    }   
}

function calc_next ($id) {
    $pos_space = strpos($id, ' ');
    $b = str_replace(' ', '', $id);  // remove space
    
    IncNextPos($b,strlen($b)-1);
    
    return substr($b,0,$pos_space) . ' ' . substr($b, $pos_space);
}

$next = 'D2 9ZW';
for ($i=0; $i<10; $i++) {
    $next = calc_next($next);
    echo $next.'<br>';
}
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#22 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 18 September 2006 - 07:57 PM

Thanks so much for eveyones time




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users