Phillip, You will have to change your code, so the primary key is not an auto incremented value. If you don't, the auto increment will over-ride the 'get next' function. Here is what I use in my code. You just need to change it for your table.
//----- GetNextKey -----// function getnextkey(){ $db = new db(); $query = "select max(MemberKey) lastkey from Members"; $result=exequery($query); if(@mysql_num_rows($result) >0){ $numrows=mysql_num_rows($result); $flds=mysql_num_fields($result); //Should only be one row, but just in case for($r=0; $r < $numrows; $r++){ $row=mysql_fetch_array($result); $lastkey = StripSlashes($row["lastkey"]); } } else { return 1; } if (is_numeric($lastkey)) { return $lastkey+1; } else { return 1; } $db->closedb(); } -----Original Message----- From: Phillip S. Baker [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 16, 2003 12:37 PM To: PHP Email List Subject: [PHP] Inserting records in a particular way in MySQL Greetings all, I have some PHP code that is inserting records into a DB. Most of this is auto increment. However I know there is allot of breaks in the sequencing. I am wondering if there is some way to write the SQL code to search through the existing records in the DB and to find where the next available ID is instead of just inserting the next sequence. So for example if the ID's are. 20453 20454 20458 20459 It would let me know that 20455 is available for use and use the ID number instead of using 20460 Thanks all. Phillip +++++++++++++++++++++++++++++++++++++++++++++++++++ IMPORTANT: This email message (including attachments, if any) is intended for the use of the individual addressee(s) named above and may contain information that is confidential, privileged or unsuitable for overly sensitive persons with low self-esteem, no sense of humor or irrational religious beliefs. If you are not the intended recipient, any dissemination, distribution or copying of this email is not authorized (either explicitly or implicitly) and constitutes an irritating social faux pas. Unless the word absquatulation has been used in its correct context somewhere other than in this warning, it does not have any legal or no grammatical use and may be ignored. No animals were harmed in the transmission of this email, although the barking dachshund next door is living on borrowed time, let me tell you. Those of you with an overwhelming fear of the unknown will be gratified to learn that there is no hidden message revealed by reading this warning backwards, so just ignore that Alert Notice from Microsoft. However, by pouring a complete circle of salt around yourself and your computer you can ensure that no harm befalls you, your family or your pets. If you have received this email in error, please add some nutmeg and egg whites, whisk and place in a warm oven for 40 minutes. +++++++++++++++++++++++++++++++++++++++++++++++++++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php