My patient number(pnum) need to have a autonumber, like BLHC-2014-0001. I need to automatically have the BLHC-current year-and auto increment of the number with 4 digits when i input new record.
Asked
Active
Viewed 149 times
-1
-
Well, Where do you store those codes/numbers? – Smuuf Jul 31 '14 at 11:35
-
on my localhost database my variable is pnum – Lea Pagkaliwangan Espinar Jul 31 '14 at 11:40
-
I don't care about the name of your variable. Post some code showing how, where and when do you need to determine a new number. – Smuuf Jul 31 '14 at 11:43
-
*Patient Number: – Lea Pagkaliwangan Espinar Jul 31 '14 at 11:47 -
I really doubt someone will be willing or capable to help you unless you really expand your question with proper information about what and how you are trying to achieve something. Now the only thing I can give you is: ```BLHC-$year-($oldNumber+1)```, but I doubt that'll help you in any way. – Smuuf Jul 31 '14 at 11:53
1 Answers
1
function autonum(){
var c ='BLHC-2014-0001';
var d = c.split("-");
var e = d[2];
var f = parseInt(e,10);
var g = f+1;
var str = '' + g;
var pad = "0000";
var resu = str.length < 4 ? (pad+str).slice(-4) : str;
var lt = d[0]+'-'+d[1]+'-'+resu;
document.getElementById("pnum").value =lt;
}

LOKESH
- 1,303
- 1
- 16
- 29
-
-
-
-
-
-
//var at = new Date(); //var aa = at.getFullYear(); //var a = '0001'; //var bb = 'BLCH-' + aa +'-'+ (a+1); – Lea Pagkaliwangan Espinar Jul 31 '14 at 12:37
-
-
-
-
-
it works, but the autonumber did not work. it always 0002 . even i save a record – Lea Pagkaliwangan Espinar Aug 01 '14 at 06:59
-
You have to retrieve last number from database into c variable. And then you have to perform this operation. – LOKESH Aug 01 '14 at 07:13
-
-
you add BLHC-2014-0001 in your database? what is your field name which save BLHC-2014-0001? – LOKESH Aug 01 '14 at 08:43
-
-
my database is dbnpatient and my table is tblnpatient – Lea Pagkaliwangan Espinar Aug 01 '14 at 08:50
-
$sql = "SELECT * FROM tblnpatient ORDER BY pnum DESC"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $pn = $row['pnum ']; break; } And in first statement of function is var c = ''; – LOKESH Aug 01 '14 at 09:26
-
-
you have to write code above javascript in php tag like and then only change the first statement of javascript write var c = ''; – LOKESH Aug 01 '14 at 09:42
-
-
-
-
-
-
-
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\pisystem\NewPatient.php on line 24 – Lea Pagkaliwangan Espinar Aug 01 '14 at 10:05
-
-
this is the line 24 while ($row = mysql_fetch_assoc($result)) { – Lea Pagkaliwangan Espinar Aug 01 '14 at 10:06
-
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\pisystem\NewPatient.php on line 9..this is the error again – Lea Pagkaliwangan Espinar Aug 01 '14 at 10:07
-
-
yes it is correct...should the $sql $result is the same to the other page/ – Lea Pagkaliwangan Espinar Aug 01 '14 at 10:20
-
'; echo '
'.$row['pnum'].' '; ?> ..this is example when i open my database – Lea Pagkaliwangan Espinar Aug 01 '14 at 10:24 -
i don't have a team viewer, but the field names and the table name is correct because i checked it to my database – Lea Pagkaliwangan Espinar Aug 01 '14 at 10:27
-
pnum,pname,addr,bdate,cont,age,fname,mname,sname,civil,sex,bp,bt,weight,complaints and date – Lea Pagkaliwangan Espinar Aug 01 '14 at 10:43
-
ok.please wait. what will i send to you? the whole page and the database? – Lea Pagkaliwangan Espinar Aug 01 '14 at 11:10
-
but the problem might be in the opening of my database in the parameter? – Lea Pagkaliwangan Espinar Aug 01 '14 at 11:14
-
-
-
-
-
-
-
-
-
how about BLCH-2015-0001, new counting if the year is new. – Lea Pagkaliwangan Espinar Aug 02 '14 at 12:23
-
I sent you mail on your email id. Check it. In that I have already done coding if year is changed. – LOKESH Aug 02 '14 at 12:42
-
yeah it works..but the counting of the number is continuing..like BLCH-2014-0010, then the next year is BLCH-2015-0011. that should be BLCH-2015-0001..new year, new counting – Lea Pagkaliwangan Espinar Aug 02 '14 at 12:46
-
-
not yet...the value of the pnum is still continuing..the BLHC-2015-0001 is appearing on the top of the banner – Lea Pagkaliwangan Espinar Aug 04 '14 at 10:47
-
-