[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Incrementing numerical part of an alphanumerical value

Hi

I have existing alphanumeric values in a mysql db field that is of the following format:

111XZY22

some examples:

12BFM02
437AFM12
1023CFZ08

the "111" can be anything from just "1" to "99999", while the "XYZ" is fixed to 3 alpha characters, and the "22" is anything between "01 and 12 - (months)"

I want to first of all determine the largest "111" value that is currently in the DB, then increment it by 1, append a $_POST var containing the alpha values and then append the last two digits to form a new alpha string.

I'm not real good with regexp etc, so I'm battling with the query as well as "extracting" just the first numerical part so I can increment it.

 
0
psimation
Asked:
psimation
1 Solution
 
MasonWolfCommented:
$query = "SELECT Value FROM Table ORDER BY Value DESC LIMIT 1";
$value = mysql_fetch_array(mysql_query($query));
$value = $value[0];

$next_num = intval(substr($value,0,3))+1;
$new_value = $next_num.$_POST['alpha'].$month;
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now