Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i developed a web page which will store

User age

in database

i want to give category for user according to the age he is entering like young,adult,old based on his/her age dynamically how can i achieve thisone

html:
name:<input type="text" id="txtname">
age:<input type="text" id="txtage">

if user enter age 18 i want to assign category to him in database dyanamically how can i do??????????
Posted
Comments
jaket-cp 2-Nov-15 5:17am    
It may be a good idea to save the date of birth instead of a fixed age.
The age of the user can be derived from the dob to a given date.

You table structure would be:

AgeCategory
ID(PK) -- Category<br />
1 -- Young<br />
2 -- Adult<br />
3 -- Old


User
ID(PK) -- Name -- AgeCategoryId(FK to the AgeCategory)<br />
1 -- ABC -- 1<br />
2 -- WER -- 2<br />
3 -- RTY -- 2<br />
4 -- FGH -- 1<br />
5 -- SDF -- 3


And you haven't specified which technology are you using for inserting the data from the HTML to DB, we can't really help on that. But the pseudo code would be,
if(txtage < 18)<br />
    // category 1 - young<br />
else if(txtage >= 18 && txtage <= 60)<br />
    // category 2 - adult<br />
else<br />
    // category 3 - old<br />
<br />
// and the fire the INSERT statement for the User table<br />



-KR
 
Share this answer
 
Use Case query..

SQL
create table categorys(age bigint,category nvarchar(15))
insert into categorys values(12,case when 12<8 then 'children' when 12<18 then 'Not adult' when 12>18 then 'adult'  end )
select * from categorys
 
Share this answer
 
v2
Comments
George Jonsson 2-Nov-15 1:18am    
Maybe add an example.
Arasappan 2-Nov-15 2:45am    
Solution updated..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900