Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to generate a unique customer id of the form c_123,c_124 and so on..


this value should be inserted in a textbox on clicking a button..
the id value should be stored in database using phpmysql to.



the table name is 'self_ticket_rising' and coulmn name is 'cust_id'

button id='click'
textbox id='cust_ids'
Posted
Comments
Herman<T>.Instance 28-Aug-15 4:44am    
What have you tried?
Member 11941750 28-Aug-15 6:20am    
i have no clue where to start. .

what i think of is that

i need to fetch last customer_id that is already present in the table and increment the value by one and check if the value is already present in database.if it is not present in the table of the corresponding database ,then store it .

thing is all this process should happen when a generate id button is clicked and the corresponding value should be popped in textbox


but then i dnt know how to code using phpmysql. . and fectch it back using json in javascript
Mohibur Rashid 28-Aug-15 4:45am    
What is your attempt or thought?
Where is your problem?
Generating the ID or setting the id to the box? or what?
Member 11941750 28-Aug-15 6:13am    
all i need is to generete a new id when i click a 'generate new id' button and then store newly generated id to the database
Member 11941750 28-Aug-15 6:20am    
i have no clue where to start. .

what i think of is that

i need to fetch last customer_id that is already present in the table and increment the value by one and check if the value is already present in database.if it is not present in the table of the corresponding database ,then store it .

thing is all this process should happen when a generate id button is clicked and the corresponding value should be popped in textbox


but then i dnt know how to code using phpmysql. . and fectch it back using json in javascript

1 solution

Add an auto-increment primary key, say id, to the table, then create the customer_id column as a Generated Column[^] the value of which derives from concatenating[^] the 'c_' with the primary key value.
+++++++++[Edit]+++++++++
Ok, try this.
1. Create a new table, say 'dummy', with only one auto-increment primary key column called id.
2. Every time you need a new customer id upon clicking a button, insert a null value to this table like this:
insert into dummy set id=null

or
insert into dummy values (null)

3. step 2 will generate a new unique id, retrieve this id using PHP mysqli_insert_id() Function[^] and concatenate it with other prefix, say 'c_', to get a unique customer id.
In this way, you are certain that no two users get the same customer id.
 
Share this answer
 
v9
Comments
Member 11941750 28-Aug-15 6:11am    
thanks for the suggestion.
i understand the flow but i dont know how to implement it


can u help?
Peter Leow 28-Aug-15 7:21am    
See improved solution 1.
Member 11941750 28-Aug-15 7:34am    
many thanks peter leow
Peter Leow 31-Aug-15 5:25am    
You are welcome.

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