bdmovies Posted October 31, 2007 Share Posted October 31, 2007 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/75470-nifty-counter/ Share on other sites More sharing options...
bdmovies Posted October 31, 2007 Author Share Posted October 31, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/75470-nifty-counter/#findComment-381924 Share on other sites More sharing options...
bdmovies Posted November 1, 2007 Author Share Posted November 1, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/75470-nifty-counter/#findComment-383090 Share on other sites More sharing options...
otuatail Posted November 1, 2007 Share Posted November 1, 2007 What you need is $u_specific +=1; str_pad($u_specific,5,'0',STR_PAD_LEFT); new_id = u_year . ($u_specific) Desmond. Quote Link to comment https://forums.phpfreaks.com/topic/75470-nifty-counter/#findComment-383116 Share on other sites More sharing options...
GingerRobot Posted November 2, 2007 Share Posted November 2, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/75470-nifty-counter/#findComment-383139 Share on other sites More sharing options...
bdmovies Posted November 2, 2007 Author Share Posted November 2, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75470-nifty-counter/#findComment-383141 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.