0

I want to create unique code iwth respect to particular selected item my unique code format is

FN1A,FN1B---------FN1Z After z loop is start again

FN2A,FN2B-----------FN2Z So on

Here i use this code

<?php

    for($row=1; $row<=22; $row++){
        echo "<tr>";
        for ($column='A'; $column!='AA'; $column++){ 
            echo "<td> $row $column </td>";
        }   
        echo "</tr>";
    }
?>

Please help me guys to create unique sample code with same format i mention in this

RichardBernards
  • 3,146
  • 1
  • 22
  • 30
  • So what's the output of your code? – u_mulder Dec 09 '14 at 08:31
  • the second part of a `for( ; ; )` statement is a test to continue, and it looks like your for loop might run forever. What does `$column++` do? When will $column become equal to 'AA' ? – RobP Dec 09 '14 at 08:32
  • possible duplicate of [Best way to list Alphabetical(A-Z) using PHP](http://stackoverflow.com/questions/2857246/best-way-to-list-alphabeticala-z-using-php) – RichardBernards Dec 09 '14 at 08:35

4 Answers4

3

Try PHP Range

<?php

        for($row=1; $row<=22; $row++){
            echo "<tr>";
            foreach (range('A', 'Z') as $char) { // Get A - Z as array 
              echo "FN{$row}{$char}";  //Concatenate as per your requirements 
             }
            echo "</tr>";
        }
    ?>
vijaykumar
  • 4,658
  • 6
  • 37
  • 54
  • 1
    Whilst correct, care to explain/add a few comments to your answer? The guy was struggling on this and an answer consisting of just code with no explanation is the minimal in usefulness – SubjectCurio Dec 09 '14 at 08:37
  • @MLeFevre I will do . Thanks !! – vijaykumar Dec 09 '14 at 08:38
  • hi i want to insert in database with respect to particular item like i have sample item1,item2,item3 item4 when i select item1 and item 2 then 2 sample code are generated fn1a,fn1b next tyme nwe user come and select 2 items then code will be fn1c,fn1d hope you clear – Sumiti Monga Dec 09 '14 at 09:06
0
  for($row=1; $row<=22; $row++){
    echo "<tr>";
    for ($column='A'; $column<='Z'; $column++){ 
        echo "<td> FN".$row . $column." </td>";
    }   
    echo "</tr>";
  }
Ajit Kumar
  • 345
  • 3
  • 9
0

I think what you are missing is the range function in php, visit http://php.net/manual/en/function.range.php for detail information, I will leave you the example I built, regards.

<?php 

$array_alb = range('A', 'Z');
$array_num = range('1', '9');

echo '<pre>';
print_r($array_alb);
echo '</pre><pre>';
print_r($array_num);
echo '</pre>';

$prefix = 'FN';
$result  = array();

foreach ($array_num as $num) 
{
    foreach($array_alb as $letter)
    {
        $result[] = $prefix.$num.$letter;
    }
}

echo '<pre>';
print_r($result);
echo '<pre>';
?> 

Array
(
    [0] => FN1A
    [1] => FN1B
    [2] => FN1C
    [3] => FN1D
    [4] => FN1E
    [5] => FN1F
    [6] => FN1G
    [7] => FN1H
    [8] => FN1I
    [9] => FN1J
    [10] => FN1K
    [11] => FN1L
    [12] => FN1M
    [13] => FN1N
    [14] => FN1O
    [15] => FN1P
    [16] => FN1Q
    [17] => FN1R
    [18] => FN1S
    [19] => FN1T
    [20] => FN1U
    [21] => FN1V
    [22] => FN1W
    [23] => FN1X
    [24] => FN1Y
    [25] => FN1Z
    [26] => FN2A
    [27] => FN2B
    [28] => FN2C
    [29] => FN2D
    [30] => FN2E
    [31] => FN2F
    [32] => FN2G
    [33] => FN2H
    [34] => FN2I
    [35] => FN2J
    [36] => FN2K
    [37] => FN2L
    [38] => FN2M
    [39] => FN2N
    [40] => FN2O
    [41] => FN2P
    [42] => FN2Q
    [43] => FN2R
    [44] => FN2S
    [45] => FN2T
    [46] => FN2U
    [47] => FN2V
    [48] => FN2W
    [49] => FN2X
    [50] => FN2Y
    [51] => FN2Z
    [52] => FN3A
    [53] => FN3B
    [54] => FN3C
    [55] => FN3D
    [56] => FN3E
    [57] => FN3F
    [58] => FN3G
    [59] => FN3H
    [60] => FN3I
    [61] => FN3J
    [62] => FN3K
    [63] => FN3L
    [64] => FN3M
    [65] => FN3N
    [66] => FN3O
    [67] => FN3P
    [68] => FN3Q
    [69] => FN3R
    [70] => FN3S
    [71] => FN3T
    [72] => FN3U
    [73] => FN3V
    [74] => FN3W
    [75] => FN3X
    [76] => FN3Y
    [77] => FN3Z
    [78] => FN4A
    [79] => FN4B
    [80] => FN4C
    [81] => FN4D
    [82] => FN4E
    [83] => FN4F
    [84] => FN4G
    [85] => FN4H
    [86] => FN4I
    [87] => FN4J
    [88] => FN4K
    [89] => FN4L
    [90] => FN4M
    [91] => FN4N
    [92] => FN4O
    [93] => FN4P
    [94] => FN4Q
    [95] => FN4R
    [96] => FN4S
    [97] => FN4T
    [98] => FN4U
    [99] => FN4V
    [100] => FN4W
    [101] => FN4X
    [102] => FN4Y
    [103] => FN4Z
    [104] => FN5A
    [105] => FN5B
    [106] => FN5C
    [107] => FN5D
    [108] => FN5E
    [109] => FN5F
    [110] => FN5G
    [111] => FN5H
    [112] => FN5I
    [113] => FN5J
    [114] => FN5K
    [115] => FN5L
    [116] => FN5M
    [117] => FN5N
    [118] => FN5O
    [119] => FN5P
    [120] => FN5Q
    [121] => FN5R
    [122] => FN5S
    [123] => FN5T
    [124] => FN5U
    [125] => FN5V
    [126] => FN5W
    [127] => FN5X
    [128] => FN5Y
    [129] => FN5Z
    [130] => FN6A
    [131] => FN6B
    [132] => FN6C
    [133] => FN6D
    [134] => FN6E
    [135] => FN6F
    [136] => FN6G
    [137] => FN6H
    [138] => FN6I
    [139] => FN6J
    [140] => FN6K
    [141] => FN6L
    [142] => FN6M
    [143] => FN6N
    [144] => FN6O
    [145] => FN6P
    [146] => FN6Q
    [147] => FN6R
    [148] => FN6S
    [149] => FN6T
    [150] => FN6U
    [151] => FN6V
    [152] => FN6W
    [153] => FN6X
    [154] => FN6Y
    [155] => FN6Z
    [156] => FN7A
    [157] => FN7B
    [158] => FN7C
    [159] => FN7D
    [160] => FN7E
    [161] => FN7F
    [162] => FN7G
    [163] => FN7H
    [164] => FN7I
    [165] => FN7J
    [166] => FN7K
    [167] => FN7L
    [168] => FN7M
    [169] => FN7N
    [170] => FN7O
    [171] => FN7P
    [172] => FN7Q
    [173] => FN7R
    [174] => FN7S
    [175] => FN7T
    [176] => FN7U
    [177] => FN7V
    [178] => FN7W
    [179] => FN7X
    [180] => FN7Y
    [181] => FN7Z
    [182] => FN8A
    [183] => FN8B
    [184] => FN8C
    [185] => FN8D
    [186] => FN8E
    [187] => FN8F
    [188] => FN8G
    [189] => FN8H
    [190] => FN8I
    [191] => FN8J
    [192] => FN8K
    [193] => FN8L
    [194] => FN8M
    [195] => FN8N
    [196] => FN8O
    [197] => FN8P
    [198] => FN8Q
    [199] => FN8R
    [200] => FN8S
    [201] => FN8T
    [202] => FN8U
    [203] => FN8V
    [204] => FN8W
    [205] => FN8X
    [206] => FN8Y
    [207] => FN8Z
    [208] => FN9A
    [209] => FN9B
    [210] => FN9C
    [211] => FN9D
    [212] => FN9E
    [213] => FN9F
    [214] => FN9G
    [215] => FN9H
    [216] => FN9I
    [217] => FN9J
    [218] => FN9K
    [219] => FN9L
    [220] => FN9M
    [221] => FN9N
    [222] => FN9O
    [223] => FN9P
    [224] => FN9Q
    [225] => FN9R
    [226] => FN9S
    [227] => FN9T
    [228] => FN9U
    [229] => FN9V
    [230] => FN9W
    [231] => FN9X
    [232] => FN9Y
    [233] => FN9Z
)
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
DiegoCoderPlus
  • 760
  • 6
  • 14
  • hi i want to insert in database with respect to particular item like i have sample item1,item2,item3 item4 when i select item1 and item 2 then 2 sample code are generated fn1a,fn1b next tyme nwe user come and select 2 items then code will be fn1c,fn1d hope you clear – Sumiti Monga Dec 09 '14 at 09:07
  • Php is stateless script, so you will need to store somehow what other user have used of the $result array i gave you, then when a new user comes, check wich are the availables codes and used then, summarizing, store result array in a database with a flag field called 'used' may be and each time a user picks up item check for the min key available wich flag is not used and assign to it and mark it in your DB with the flag. remember php is stateless, you store states info in DB or use SESSION, or COOKIE or FILES or YIELD generators if you are using 5.5 to overcome that fact, regards – DiegoCoderPlus Dec 09 '14 at 10:30
0

I know about the concatenate guys you concatenate with my logic but I have form with particular samples one i select the sample from dropdown one unique code genrate and insert into database