How to insert english alphabets as incremental order How to insert english alphabets as incremental order codeigniter codeigniter

How to insert english alphabets as incremental order


Check this similar article:

Algorithm to get the excel-like column name of a number

Here's a nice simple recursive function (Based on zero indexed numbers, meaning 0 == A, 1 == B, etc)...

function getNameFromNumber($num) {    $numeric = $num % 26;    $letter = chr(65 + $numeric);    $num2 = intval($num / 26);    if ($num2 > 0) {        return getNameFromNumber($num2 - 1) . $letter;    } else {        return $letter;    }}And if you want it one indexed (1 == A, etc):function getNameFromNumber($num) {    $numeric = ($num - 1) % 26;    $letter = chr(65 + $numeric);    $num2 = intval(($num - 1) / 26);    if ($num2 > 0) {        return getNameFromNumber($num2) . $letter;    } else {        return $letter;    }}

Tested with numbers from 0 to 10000...


It's quite easy that you use php to implement this,please check codes below

$i = 'A';echo $i;echo PHP_EOL;while($i != 'ZZ'){ echo ++$i; echo PHP_EOL;}

or see the results in http://codepad.org/QB4kyV7U


Sounds a lot like this SO article

MYSQL: how to "reorder" a table

Is there an absolute necessity to do what you are wanting when you can use sorting to output your data however you want?