Jump to content

Recommended Posts

This thing has given me so much trouble.......I'm trying to get a counter that does the following

 

Grabs the last uniqueID from the table (formatted 200700001, 200700002...)

Seperate into 2 variables, u_year and u_specific

If the current year matches u_year then new_id = u_year . (u_specific +1)

If the current year is greater than u_year, the new_id = $year . "00001"

If the current year is less than the u_year Stop everything.

 

Sounds easy enough, but I'm running into problems. First I would get everything to work up to the point where I add one to the existing u_specific, it always took away my 0000, so I would get 20072, 20073.....

 

I tried a workaround, but it's quite a bit of code, and it just stops at 100.

 

<?php
// Gets the last UniqueID
$query = "SELECT * FROM case_information ORDER BY uniqueID DESC LIMIT 1";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$last_unique_id = $row{'uniqueID'};
$l_uid_year = substr("$last_unique_id", 0, 4);
$l_uid_specific = substr("$last_unique_id", -5);
$year = date('Y');

/*
if ($l_uid_year == $year) {
$n_uid_specific = $l_uid_specific + 1;
$n_uid_year = $year;
}
elseif($l_uid_year > $year) {
$n_uid_year = $year;
$n_uid_specific = "00001";
}
elseif($l_uid_year < $year) {
die("Check server clock");
}

*/
if ($l_uid_specific < "00009") {
$n_uid_specific = "0000" . ($l_uid_specific + 1);
$n_uid_year = $year;
}
elseif ($l_uid_specific < 100 and $l_uid_specific > 10) {
$n_uid_specific = "000" . ($l_uid_specific + 1);
$n_uid_year = $year;
}
elseif ($l_uid_specific < 1000 and $l_uid_specific > 100) {
$n_uid_specific = "00" . ($l_uid_specific + 1);
$n_uid_year = $year;
echo "Hello";
}
elseif ($l_uid_specific < 10000 and $l_uid_specific > 1000) {
$n_uid_specific = "0" . ($l_uid_specific + 1);
$n_uid_year = $year;
}
elseif ($l_uid_specific > 10000) {
$n_uid_specific = $l_uid_specific + 1;
$n_uid_year = $year;
}
elseif ($l_uid_specific == "00009") {
$n_uid_specific = "000" . ($l_uid_specific +1);
$n_uid_year = $year;
}
elseif ($l_uid_specific == "00099") {
$n_uid_specific = "00" . ($l_uid_specific +1);
$n_uid_year = $year;
}
elseif ($l_uid_specific == "00999") {
$n_uid_specific = "00" . ($l_uid_specific +1);
$n_uid_year = $year;
}
elseif ($l_uid_specific == "09999") {
$n_uid_specific = "0" . ($l_uid_specific +1);
$n_uid_year = $year;
}
elseif ($l_uid_specific == "99999") {
$n_uid_specific = $l_uid_specific +1;
$n_uid_year = $year;
}


$uniqueID = $n_uid_year . $n_uid_specific;

echo "The last unique id is $last_unique_id<br>";
echo "The last year is $l_uid_year<br>";
echo "The last specific is $l_uid_specific<br>";
echo "The new specifc is $n_uid_specific<br>";
echo "The new year is $n_uid_year<br>";
echo "The uniqueID is $uniqueID";
?>

 

Link to comment
https://forums.phpfreaks.com/topic/75470-nifty-counter/
Share on other sites

First I would get everything to work up to the point where I add one to the existing u_specific, it always took away my 0000, so I would get 20072, 20073

 

Personally i think thats a good thing. What happens with your present system if the unique number exceeds 99,999 in each year? While its probably unlikely, it would be better to design it such that you wouldn't have a problem with a larger number.

Link to comment
https://forums.phpfreaks.com/topic/75470-nifty-counter/#findComment-383139
Share on other sites

First I would get everything to work up to the point where I add one to the existing u_specific, it always took away my 0000, so I would get 20072, 20073

 

Personally i think thats a good thing. What happens with your present system if the unique number exceeds 99,999 in each year? While its probably unlikely, it would be better to design it such that you wouldn't have a problem with a larger number.

 

Yes, I have thought about that, but the chances that any company will exceed 99,999 cases is crazy, and if they do, chances are they aren't using my system :)

Link to comment
https://forums.phpfreaks.com/topic/75470-nifty-counter/#findComment-383141
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.