T
|
tedwilder 3/14/2011 |
hello |
J
|
joker author 3/14/2011 |
hello Im not 100% sure I understand your request. But from I get you need one auto created number and then severals field that are filled with same previous number. It's my choice to never use the autoincremential field for my own data in mysql because it's a lot of trouble like the one you are experiencing. of course I keep an auto incremential id but it's for internal purpose only It's not showned in my project neither . I never use it . It's just for the sake of mysql internal working. I use my own script to create incremential numbers this way I'm free to edit things a lot easier specialy when it comes to edit datas with a thirs party mysql front ( navicat/phpmyadmin). Just my opinion though.. So to create a new number that is based on previous record : 1/ in event " before process" retrieve the last number ( here it's an example based on my own field format that are : CR201103001 for today for isntance ) $sql="select max(substr(numcourrier,9)) as mx from courrier where substr(numcourrier,7,2)=month(now()) order by mx"; $rs=CustomQuery($sql); $data=db_fetch_array($rs); $str="CR"; $str2=date("Ym"); $str3=($data["mx"]+1); $_SESSION["numcourrier"]= "$str$str2".str_pad($str3, 5, 0, STR_PAD_LEFT); $_SESSION["numcontenu"]=$_SESSION["numcourrier"]; 2/ as you can see I put the value in a session variable, so when the add page is loaded I can use them to set the default field value to my new next available number in a read only field so user cant change the number . so if you need severals fields to have same values as master field just put " $_SESSION["numcourrier"] " in editor under "default value " for this field. 3/ Of course now 5.3 has autofill so you can create lookup field and check autofill : it will enter values it has retrieve from another table or same table. Hope this will help u to find a solution.
|
T
|
tedwilder 3/14/2011 |
well it's quite easy : I dont have such problem because I never have 2 users entering at the same time data. |
J
|
joker author 3/15/2011 |
well it's quite easy : I dont have such problem because I never have 2 users entering at the same time data. howevever you can : 1/ enabling table locking in phprunner : record is locked when a user is using it so a another user wont be able to create a record at the same time. ( I enjoy phprunner however I noticed severals time this function is somethimes buggous) 2/ if you need severals user to be able to create record at the same time and to generate new numbers for each you need to create a ( at least it's what comes to my mind right away) temporary table : in the before process right after the code that define your number, you need to insert that number into your temporary table ( very easy : $sql = " insert into sometemptable where shippingnumber=".$SESSION_["numbercreate above"] (execept the 1st line of code in previous post will look into the temporary table instead of real record) This way the user can stay on the add page as long as he wants, if another user wants to also add a record at the same time while 1st user has not finished , he will get the last created number from temporary table + 1 . When user has filled the whole form and is ready to close/ validate the manifest , in the event "after record" you can delete the previous temporary field with a simple $sql DEL ..where number= $SESSION .. and clear session variable. this way any user at any time always get the next number available without creating conflict. I guess you could also fine tuning it in case a user start a manifest but never close it,( computer crash and has to be restarted for instance ) you should adding in the tomporary table a userowner field and statut field ( ex 1 for recorded 0 for in progress).this way if you edit before process php accordingly you could retrieve the number that was affected to user prior crash). I guess we both agree that it would be nice if phprunner had an autonumbering customized function embedded <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=57071&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
|