the-botman Posted September 14, 2012 Share Posted September 14, 2012 hey guys seems i have a small problem, see this is how i add a unique Id but it ends up to long function GetGuid() { $Date = date('Y')."-".date('m')."-".date('d'); $Time = date('H')."-".date('i')."-".date('s'); $Str = "$Date-$Time-"; $Guid = str_replace('-', '', uniqid($Str, TRUE)); $Guid = str_replace('.', '', $Guid); return $Guid; } is there a way to make it little shorter? and will it be a safe option. thanks in advance zainul Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 14, 2012 Share Posted September 14, 2012 Why don't you just use an auto increment field? And why are you adding "-" just to take them out?? Quote Link to comment Share on other sites More sharing options...
lemmin Posted September 14, 2012 Share Posted September 14, 2012 What are you trying to accomplish? What is too long? $Guid = uniqid(date('YmdHis'), true)); return strtr($Guid, '.', ' '); There. I made it shorter! I think the string that uniqid() returns actually contains the input string at the beginning so you could remove that if you want: $Guid = substr($Guid, 14); It all depends on what you are trying to do with it. Quote Link to comment Share on other sites More sharing options...
the-botman Posted September 14, 2012 Author Share Posted September 14, 2012 this was the only way i knew how to set unique Gbk_Id`s for each entry, i found it to be to long but never really tried any other way untill i started upgrading my guestbook. so when ever i am adding an entry i do it like.. $Name = GetPost('Name'); $Message = GetPost('Message'); if ($Name != "" && $Message != "") { $Entry_ID = GetGuid(); $Entry_Date = date('Y')."/".date('m')."/".date('d'); $Entry_Time = date('H').":".date('i').":".date('s'); $DbRes = MySqlCmd("INSERT INTO page_guestbook VALUES ('$Entry_ID','$Entry_Date','$Entry_Time','$Name','$Message')"); and the getguid is like this function GetGuid() { $Date = date('Y')."-".date('m')."-".date('d'); $Time = date('H')."-".date('i')."-".date('s'); $Str = "$Date-$Time-"; $Guid = str_replace('-', '', uniqid($Str, TRUE)); $Guid = str_replace('.', '', $Guid); return $Guid; } Quote Link to comment Share on other sites More sharing options...
the-botman Posted September 14, 2012 Author Share Posted September 14, 2012 i rather just do it as jesirose said maybe this is the way you ment? function GetGuid() { $Guid = uniqid($Str, TRUE); return $Guid; } Quote Link to comment Share on other sites More sharing options...
Christian F. Posted September 15, 2012 Share Posted September 15, 2012 You want to use MySQL's AUTO_INCREMENT for this. 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.