Giving a customer an ID number
Moderator: General Moderators
Giving a customer an ID number
OK, I have a client list stored in a MySQL database and each time a new row is entered it auto_increases the ID column. So now the client has an ID number
However, I want to be able to do this before entering their name into the database, making sure that the number they are given is only ever used once.
Any help appreciated
Ian
However, I want to be able to do this before entering their name into the database, making sure that the number they are given is only ever used once.
Any help appreciated
Ian
As long as you have auto_increment on, when you do the first MySQL query (such as right after the customer has registered) just leave the ID field blank and MySQL will take care of the rest.
so:
Then whenever you retrieve info from the database first, just make sure you keep the $id and then later use it to update the database.
so:
Code: Select all
<?php
$query = "INSERT INTO table VALUES ('','$customername','$customerinfo')"; // the first '' is where the id column is
?>Just adding the following based on DuFF's post:DuFF wrote:As long as you have auto_increment on, when you do the first MySQL query (such as right after the customer has registered) just leave the ID field blank and MySQL will take care of the rest.
so:Then whenever you retrieve info from the database first, just make sure you keep the $id and then later use it to update the database.Code: Select all
<?php $query = "INSERT INTO table VALUES ('','$customername','$customerinfo')"; // the first '' is where the id column is ?>
Look that one up for more info. Might be interesting.PHP Manual wrote: mysql_insert_id() returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query using the given link_identifier. If link_identifier isn't specified, the last opened link is assumed.
it is unique... but once one is deleted.. then the numbers go all screwed... like if u had 10, 11, 12, 13 and u deleted 11, then it would be weird...aquila125 wrote:if you have MySQL, the auto_increment field IS unique.. nothing you can do about it... it's MUCH safer to let mysql handle this then to do it in PHP...
why would it be weird, all numbers would be still unique.
Does it matter that customer id numbers are in sequence!?
Mark
Does it matter that customer id numbers are in sequence!?
Mark
Last edited by JayBird on Thu Dec 11, 2003 5:51 am, edited 1 time in total.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
That shouldn't make any difference to you it's just an identifier for that row - reusing unique id's is a bad idea and if your display depends on unique id's being sequential then you need to change your code so that it doesn't.AnsonM wrote:it is unique... but once one is deleted.. then the numbers go all screwed... like if u had 10, 11, 12, 13 and u deleted 11, then it would be weird...aquila125 wrote:if you have MySQL, the auto_increment field IS unique.. nothing you can do about it... it's MUCH safer to let mysql handle this then to do it in PHP...
Mac