1

I have a field outlet_id having values like this:

AA1
AA2
AA3
AA4

It's not mysql auto incrementing field. I have to fetch the last value inserted into the outlet_id and increment it like AA5,AA6,AA7 ...

What I have done so far is:

$sql_outlet_id=mysql_query("SELECT MAX(outlet_id) FROM outlets");
$val = mysql_fetch_row($sql_outlet_id);
$new_array = explode('AA',$val[0]);

echo $outlet_id=$new_array[1]+1;

Output always shows 10 even if last inserted id is AA20 or AA21 or so on.

1 Answer 1

2

Try with -

$val = 'AA4';

$temp= str_replace('AA', '', $val);

$new = 'AA' . ($temp + 1);

echo $new;

Output

AA5
Sign up to request clarification or add additional context in comments.

3 Comments

how to fetch the last value from database like AA4 @sougata
Is there any field that is auto incremented? like id, date or something like this?
ya i got it id is auto incremented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.