Increment integer value

QuestionsIncrement integer value
Daniele asked 12 years ago

hello,
I used this function to increment a MySQL integer value in a table, the function returns the maximum value to me and adds a number, and then increase the value, because it only works when I add the first record and the next not? If I add the first record (example 11) is fine, if I add another I always 11.

thanks.

$queryMax=mysql_query("SELECT MAX(NUMERO+1) FROM schederivenditori WHERE IDUTENTE = $id_user");
$row = mysql_fetch_row($queryMax);
$numScheda = $row[0];
$col["editoptions"] = array("value"=$numScheda);

5 Answers
Abu Ghufran answered 12 years ago

One thing that looks to be an issue is the sql
Perhaps, It should be MAX(NUMERO)+1 not MAX(NUMERO+1)

$queryMax=mysql_query("SELECT MAX(NUMERO)+1 FROM schederivenditori WHERE IDUTENTE = $id_user");

Also, can you confirm if the correct data is set as default or not. If it is not, you can confirm running query in phpmyadmin or similar that if it is return desited maxid+1.

Let me know the result.

Daniele answered 12 years ago

The function of Mysql is correct even so, I use often, I did the test as you said but nothing changes. If I try directly from the MySQL server with Sequel Pro and the query works fine in both cases, there is always the problem when I insert the next record.
thanks

Abu Ghufran answered 12 years ago

Is you case resolved? If not, we can setup a remote desktop session.
Let me know soon.

Thanks

Daniele answered 12 years ago

I'm sorry but I have not solved yet, I am available immediately

Abu Ghufran answered 12 years ago

Changed implementation to use on_insert event for data updating.

Closing this ticket after live support resolution.

Your Answer

17 + 20 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?