Can you use max within a select function? This is where I have it... $cd_qry = 'select max(code) from equipment'; connecttodb(); $result = mysql_query($cd_qry); $temp = mysql_fetch_row($result); $bcode = $BCODE_START . str_pad((substr($temp[0], -6) + 1),6,'0',STR_PAD_LEFT); However, I'm getting an error that says "Supplied argument is not a valid MySQL result resource in /usr/local/nusphere/apache/htdocs/ese-lab/Protect/add.php3 on line 162". The line beginning with $temp is line 162... would this be why? I'm using MySQL 3.23.33 and PHP 4.0.4 . Thanks, Liz -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]