Forums

Generate number

Yudhizth 21 Nov, 2014
Dear All,

I have registration page.
after registration it would be generate no_permohonan automatically.
How to generate no_permohonan like on the picture

Example:
04002614

04 : id_nama_ijin
0026 : auto increment depends on max number id_nama_ijin
14 : current year

Thanks
GreyHead 21 Nov, 2014
Hi Yudhizth,

You can build this with PHP in a Custom Code action but I have no idea how you plan to manage the auto-increment part?

Bob
BNDragon 21 Nov, 2014
Hi there,

If the number is always the same size (same number or digits) it's quite easy, just convert to string, explode it and convert it again to number.

Explaining in more detail:

1 -> Convert number to String
2 -> Explode the string in 2 + 4 + 2
3 -> Convert to Int 2nd token explode (item [1])
4 -> increment token
5 -> convert to String token
6 -> result = item [0] "" item [1]. "." entry [2]..;
7 -> Convert the result to int

It's not very hard to do it, but give some work.
Other option is create a simple table, with "id_nama_ijin" and "autoIncrement".

BN
Yudhizth 26 Nov, 2014
Greyhead : Do you have an example? I have no idea to create it.
BNDragon :The number is dynamic, when user register, the data will continuing.
id_nama_ijin is on master table. I only understand on point 6, I am not so familiar with web programming language

Thanks
BNDragon 26 Nov, 2014
Hi Yudhizth ,

The point 6 was serevel changed by the translator, I didn't saw that

6 -> result = item [0] "" item [1]. "." entry [2]..;


Should be 6 -> result = item [0]."".item [1]."".item[2];

Just create a table with an id_nama_ijin field and an autoIncrement field. The idea is when you will generate the no_permohonan number, you just make a db query like:
select autoIncrement from table where id_nama_ijin="ID"
and you got your autoIncrement value.

BN
Yudhizth 01 Dec, 2014
All right, I get the point.
I have to create transaction table with id (autoincrement) and id_nama_ijin (static)
But I confused when decide the parameter

I'm using combobox to input value of id_nama_ijin and how to determine autonumber based on id_nama_ijin?

Imagine that this is first time I use this system.

for example, I choose id_nama_ijin with value 04, and then autonumber is 001 and year 14.
When I choose another id_nama_ijin 03; the autonumber is 001 not 002, because it based on id_nama_ijin.

Sorry if you're not understand

Thanks
BNDragon 01 Dec, 2014
Hi Yudhizth ,

Imagine this db table structure:
id_nama_ijin || autonumber


Is all you need, because then is just incremente the autonumber every time you chose the id_nama_ijin, so, if the user select id_nama_ijin=01, using a dbquery you get the autonumber from id_nama_ijin, then save it and finally using another dbquery increment the autonumber of id_nama_ijin.
Some like this would work i think
<?php
$con=mysqli_connect("localhost","root","","YOUR_DB_NAME");
	// Check connection
	if (mysqli_connect_errno())
	{
		echo "Error: " . mysqli_connect_error();
	}

	$autoN = mysqli_query($con,"SELECT autonumber FROM #__nama_ijin WHERE id_nama_ijin='".$form->data["yourValue"]."'");
	
	$line = mysqli_fetch_array($autoN);
	
	$number=$line['autonumber'];
	$incN=$number++;
	
	$upAutoN = mysqli_query($con,"UPDATE #__nama_ijin SET autonumber='".$incN."' WHERE id_nama_ijin=".$form->data["yourValue"]."'");

	


I dind't test the code, so please, test it and debug if needed, and the $form->data["yourValue"] var is your box value. Don't forget to set the right values in $con.
In the end I think that the number var will have your autoNumber and in you db table it'll be updated.

BN
This topic is locked and no more replies can be posted.