Jump to content

Unique ID's and Group ID's


bdmovies

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.