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. ;-)


PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to