Re: I need to get the MAX value of something...

From: Date: Fri, 24 Nov 2000 19:11:56 +0000
Subject: Re: I need to get the MAX value of something...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-27005@lists.php.net to get a copy of this message
> I have entries like 804A3333 in the database, check the following code: > > $indexq = mysql_query("SELECT > MAX(substring(indexvar,5)+1) indexvar1,substring(indexvar,1,4) indexvar2 > What this is supposed to do, is to get the biggest number which comes > after 804A and add one to it. However, it seems to work most of the time, > but well...right now I have mainly entries like 804A11111 and now someone > changed one $index in the input field to 804A (without any numbers after I'm guessing that MySQL is doing something funky for substring() with invalid inputs... I would try: max(substring(indexvar,5)) + 1 Or, typecasting substring(indexvar,5) to an integer and then doing the max/+1 I dunno how to typecast in MySQL. In the docs. http://mysql.org

« previous php.general (#27005) next »