bdmovies Posted October 5, 2007 Share Posted October 5, 2007 So I've got a table that will contain case_numbers for different court cases. I need to make every entry a Unique ID, but for specific reason it just can't be the basic auto_increment. Long story short, I basically insert the case informaiton run a mysql_insert_id() get the last id (I do have an auto_increment field) run some conditional statements to get to this $year . '0000' . $last. Basically, it looks like this: 200700001, 200700002 or 200700030 or 200701000, basically the year, followed by 5 numeric spaces(so in theory you can 99,999 cases in a year without running into ID issues). Now, that part was simple and it's unique ot EVERY insert. But, sometimes there are multiple people in a case (ex. John Doe and Mary Doe) I need to get a caseID so users can query for the caseiD and get both John and Mary Doe. Below is basically everything I just said, the problem I'm running into, is when I insert the same case_number it grabs the mysql_id and uses that as a counter, so I'm doing the same thing as the uniqueID. I think the code will explain it better than I did <?php //INSERT THE INFORMATION $database_values = "date_created, case_number, plaintiff, defendant, county_issued, state_issued, document_type, person_to_be_served, address_one, address_two, city, state, zip, client_reference, status, comments, clientID, attorneyID, serverID"; $insert_values = "'$date', '$case_number', '$plaintiff', '$defendant', '$county_issued', '$state_issued', '$document_type', '$person_to_be_served', '$addressone', '$addresstwo', '$city', '$state', '$zip', '$client_reference', '$status', '$comments', '$row_client[clientID]', '$row_attorney[attorneyID]', '$row_server[serverID]'"; $query = "INSERT INTO case_information (date_created, case_number, plaintiff, defendant, county_issued, state_issued, document_type, person_to_be_served, addressone, addresstwo, city, state, zip, client_reference, status, comments, clientID, attorneyID, serverID) VALUES ('$date', '$case_number', '$plaintiff', '$defendant', '$county_issued', '$state_issued', '$document_type', '$person_to_be_served', '$addressone', '$addresstwo', '$city', '$state', '$zip', '$client_reference', '$status', '$comments', '$row_client[clientID]', '$row_attorney[attorneyID]', '$row_server[serverID]')"; mysql_query($query) or die(mysql_error()); $last = mysql_insert_id(); $lastID = mysql_insert_id(); $case_id_query = mysql_query(SELECT * FROM case_information); $case_id_result = mysql_fetch_array($case_id_query); $case = $case_id_result['caseID']; $year = date('Y'); if($last < 10) { $last = $year . '0000' . $last; } elseif($last < 100 and $last > 9){ $last = $year . '000' . $last; } elseif($last < 1000 and $last > 99){ $last = $year . '00' . $last; } elseif($last < 10000 and $last > 999){ $last = $year . '0' . $last; } else { $last = $year.$last; } if($case < 10) { $case = $year . '0000' . $case; } elseif($case < 100 and $case > 9){ $case = $year . '000' . $case; } elseif($case < 1000 and $case > 99){ $case = $year . '00' . $case; } elseif($case < 10000 and $case > 999){ $case = $year . '0' . $case; } else { $case = $year.$case; } $query_unique_id = "UPDATE case_information SET uniqueID='$last' WHERE internalID = '$lastID'"; mysql_query($query_unique_id) or die(mysql_error()); $query_case_id = "UPDATE case_information SET caseID='$case' WHERE case_number = '$case_number'"; mysql_query($query_case_id) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/71913-unique-ids-and-group-ids/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.