Re: generating sequence without AUTO_INCREMENT

From: Date: Thu, 26 Jun 2003 21:15:21 +0000
Subject: Re: generating sequence without AUTO_INCREMENT
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-28929@lists.php.net to get a copy of this message
MAX(issue_number)+1 where YEAR(date) = Year(NOW())
I continued to work while waiting for ideas, and have now manage to get a script that work. I'm getting the next issue number this way: // Connect to database to get latest issue number from table un_issue db_connect($dbuser, $dbpassword, $dbdatabase); $query = "SELECT * FROM un_issue ORDER BY i_id DESC LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_row($result); $next_issue_number = $row[2] + 1; $previous_issue_date = $row[1]; I didn't think of the problem when two users are adding at the same time since this won't happen in this particular case. But what could I do to avoid the problem in future scripts? Doing what I wanted to do took six hours and 120 lines of code, all in all, but I learnt a good deal on the way. ;-) //Anders

« previous php.db (#28929) next »