bdmovies Posted October 18, 2007 Share Posted October 18, 2007 Ok, I know I'm asking stupid questions, but please bear with me, I'm only a baby PHP programmer. I've got a uniqueID for every Summons I input into the DB. The way I'm doing this counter is something like this. QUERY get the last uniqueID Split the unique ID into 2 parts. 1st = 2007 2nd = 00001 (the first part is the current year, the 2nd part, i'm calling the serial#) so now I have $id_year and $serial If the $id_year == current year then $serial == $serial +1 elseif $id_year < current year then $serial == 1 elseif $id_year > current year STOP EVERYTHING, THE COMPUTER DATE IS WRONG implode the $id_year and $serial into $unique_id later on in the code, you insert the unique_id into the next row along with the rest of the information Ok, so I know it doesn't look pretty, but I haven't written the code yet. My question is how can I split the 200700000 into 2007 and 00000? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 18, 2007 Share Posted October 18, 2007 http://us2.php.net/manual/en/function.substr.php as long as the length is always the same it will never fail you. Quote Link to comment Share on other sites More sharing options...
SammyGunnz Posted October 18, 2007 Share Posted October 18, 2007 <?php $string = '200700000'; $year = substr($string, 0, 4); $serial = substr($string, 4, 5); ?> Quote Link to comment Share on other sites More sharing options...
SammyGunnz Posted October 18, 2007 Share Posted October 18, 2007 Yeah, what cooldude832 said. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 18, 2007 Share Posted October 18, 2007 I try and help by not giving the exact solution so a person learns a new function and doesn't ask another question regarding it because they figured it out on their own, but yes that is the exact solution. Quote Link to comment Share on other sites More sharing options...
bdmovies Posted October 18, 2007 Author Share Posted October 18, 2007 Thanks all of you, and cooldude, don't worry, I actually do go and learn things, I don't like just knowing, but Id like to know how and why. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 18, 2007 Share Posted October 18, 2007 thats good, I hate it when people paste in code they "found" and expect a working answer, not an answer to how it works. Quote Link to comment Share on other sites More sharing options...
bdmovies Posted October 18, 2007 Author Share Posted October 18, 2007 Yeah, that's why I tend to ask so many questions. I'd much rather know how to do something on my own and understand the theory behind it then to just know code. What good is just knowing the bare bones to get by? Quote Link to comment Share on other sites More sharing options...
bdmovies Posted October 18, 2007 Author Share Posted October 18, 2007 Do you have any suggestions for learning OOP? I have absolutely NO experience in OOP, and to be quite honest don't quite understand the logic behind it, but I do know it's something that apps tend to be written in. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 18, 2007 Share Posted October 18, 2007 php actually has a lot of modules that you will never use (like the hypewave functions), but its good to know all the modules so when the day comes you can say oh that could be useful. Even inside each module there are tons of functions considered useless or so specific they can't be used. One that comes to mind is the array functions, many of these are over kill and you don't need them beyond the basics, but knowing that php.net has a list of all these you never know when u might use one. Just the other day I found a use for http://us.php.net/manual/en/function.array-pop.php that saved me a few lines in a pagination display. Knowing the bare minimal isn't good, the trick is to have a general idea about structure and usage for most things and you can get by very easily. That and using good structure in coding so you can see errors very easily. I don't ever use OOP so I wouldn't be a help to you. Quote Link to comment Share on other sites More sharing options...
bdmovies Posted October 18, 2007 Author Share Posted October 18, 2007 Yea, I really enjoy knowing the ins and outs of everything. Although, I'm a self-taught programmer, so knowing all of that is rather difficult, I found it's just a lot of learning as I go. I know the code for the app I'm writing now most likely sucks, but I'm learning, and I'll just sit there and fix what needs to be fixed and re-write what needs to be re-written.... Quote Link to comment 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.