i want to generate a student id,
this is my code

it is saving but, no output in dB.

$yr=date('Y');
	$id=mysql_insert_id();--auto_increment
	$b="MATH"."$yr"."$id";
	$a=$_POST['b'];

	MATH201201 -- i want my output to be this,

Recommended Answers

There are no leading zeros in auto-incremented ids so you will only ever get MATH 20121 as your code is. If you want to include a zero you will have to put it in

$b="MATH"."$yr".0."$id";
Jump to Post

All 3 Replies

There are no leading zeros in auto-incremented ids so you will only ever get MATH 20121 as your code is. If you want to include a zero you will have to put it in

$b="MATH"."$yr".0."$id";
Member Avatar

As broj1 put it, string padding will probably be the way to go with this. However, your format will limit capacity to 99 users. I can't see what you're trying to do with the post and variable, but anyway, you're better off not using any padding, or if you have to, ensure that the padding is sufficiently big to allow as many users as you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.