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

From: Date: Fri, 24 Nov 2000 14:33:17 +0000
Subject: I need to get the MAX value of something...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-26959@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 FROM main WHERE substring(indexvar,1,4)='804A' GROUP by indexvar desc"); while($something = mysql_fetch_array($indexq)){ $indexone = $something["indexvar1"]; $indextwo = $something["indexvar2"]; } $index = $indextwo.$indexone; 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 it) and now the counting starts again from 804A instead of 804A11111. Yes, I could probably just get rid of the textbox and show just the value, but any ideas how to make this little 'system' work without any possible mistakes? Thanks in advance, Siim EInfeldt

« previous php.general (#26959) next »