0

How I can increment a letters if value already in the database? Just like in my database structure AA, AB, AC and the next value should be AD.

How to check the value and increment the value?

Database Structure

id  |  code |   
1   |  AA   |  
2   |  AB   |  
3   |  AC   | 

Example Code

<input name="maincode" value="<?php
    $mysqli = new mysqli("localhost", "root", "", "2015");

    $result = $mysqli->query("SELECT code FROM category
    WHERE code != '' ORDER BY code");

    $var = 'aa';
    do {
      echo $var++.'<br />';
    } while ($var != 'aaa');

The next value should be AD

BenMorel
  • 34,448
  • 50
  • 182
  • 322
user3097736
  • 284
  • 5
  • 23

1 Answers1

0
$data= "AC";
$data++;
echo $data; //AD

you should use google :)

page 1

page 2

page 3

Incrementing/Decrementing Operators

Now, to select the last value, in this case AC

$query = "SELECT code FROM table_name ORDER BY id DESC LIMIT 1";

//this should return the last record

To sum both letter

str_split

$data= "AA";
$letter= str_split($data);
$letter[0]++;
$letter[1]++;
echo $letter[0].$letter[1];
Community
  • 1
  • 1
kraysak
  • 1,746
  • 1
  • 13
  • 14