473,408 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

generate autoid

Hi all
i am new to mysql and php.
i want an urgent help.
i am developing an application for an training centre.
i want to maintain a student table. To which i only enter his/her name and address, my requirement is it will generate students rollno. automatically.
according to the following condition
1.the 1st noumber of the rollno should be state code.
2.the second number of the rollno should be center code.
and then an auto increament number.
i have state code table and center code table.

state code;-
state code | state name
01--------|-----aaa
02--------|------bbb
03--------|-------ccc

centre code:-
centre code | center name
01-------|------xxx
02-------|-------yyy
03-------|-------zzz
fro example
if the state name is "aaa" and center nane is 'yyy" then the roll number
will be like :-0102-0001. (01 state code,02 center code, 0001-an auto increament no.)
any help is appreiciated.

thanks
abhaya
Oct 18 '08 #1
1 2758
Atli
5,058 Expert 4TB
Hi abhaya.

When you say automatically, I assume you mean that you will be providing the state and centre codes, but the additional integer be created automatically?

If so, you would probably be best of simply creating a noraml Integer Auto_Increment Primary Key column and two Foreign Key columns for the state and centre ID's.

Then you could simply CONCAT them together to get your rollno.

And keep in mind that if you create a integer column that specifies the length of the number and Zerofill, MySQL will automatically pad the number with zeros to make it exactly that many characters long when selected.

Like for example, these three commands:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE `myTable` (`Integer` Int(4) Zerofill);
  2. INSERT INTO `myTable` VALUES (1), (2);
  3. SELECT * FROM `myTable`;
  4.  
would output something like:
Expand|Select|Wrap|Line Numbers
  1. +---------+
  2. | Integer |
  3. +---------+
  4. |    0001 |
  5. |    0002 |
  6. +---------+
  7.  
That might help you format your output.
Oct 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Almoni | last post by:
Hi, I have a few .xsd files that include each other in the following way: <!-- lets call the main schema file AA.xsd and it includes BB.xsd inside it --> <xs:schema...
3
by: Garry Dawkins | last post by:
Hey Frank, I'm a novice with this taking over someone elses application. I'm attempting to add a dataset to a page. I have the query to populate the page and I have the walkthrough instructions. ...
1
by: jtsree | last post by:
I am Using (Windows XP) Visual Studio.net 2003 professional edition working on VB.net language. I am bulding a very very simple project in VB.net where i connect to Access Database by dragging...
9
by: Henk Verhoeven | last post by:
We are not alone! "Where other MDA tools are generating programmingcode, Codeless chooses not to generate code at all". OK, phpPeanuts is not an MDA tool (it has no fancy modeling GUI). But it...
4
by: Stephen | last post by:
I need to generate input XML for another application by serialising classes defined in an XSD document. The code below will generate the XML I require but I need to generate this in memory rather...
0
by: DD | last post by:
I have a table in a split database MS A 2002 that has to have the following fields before the AutoID -2 Test -1 TEST2 0 TEST 3 AutoID Company Name The count starts at 1 and runs until it gets...
1
by: A Traveler | last post by:
Hello, i am having this problem. The exact error message is: "Unable to generate code for a value of type 'System.Web.UI.Page'. This error occurred while trying to generate the property value for...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
2
by: bthubbard | last post by:
This may not be the best group in which to post this. If there is a better location please direct me there. I have been experimenting with Sandcastle to generate CHM help file documentation for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.