473,464 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

copy auto_increment value to another field

Hi,

i want to create a unique serial number to my Db entries. I thought
the best way would be to add the auto_increment primary key value to a
string, then insert it into a table field 'serial_num'.

$serial_num = "NAME000" . $auto_increment_value;

Is this possible in one function? Or do I have to insert all the other
data first, then get the last inserted id value and then update the
entry with the $serial_num variable?

Cheers
Jul 17 '05 #1
5 3062
Nel
"Paul Lamonby" <pa**@popimages.com> wrote in message
news:86**************************@posting.google.c om...
Hi,

i want to create a unique serial number to my Db entries. I thought
the best way would be to add the auto_increment primary key value to a
string, then insert it into a table field 'serial_num'.

$serial_num = "NAME000" . $auto_increment_value;

Is this possible in one function? Or do I have to insert all the other
data first, then get the last inserted id value and then update the
entry with the $serial_num variable?

Cheers


Hi Paul,

If you set one field type, lets call it "id", to an INT and set
auto_increment, primary, unique, this would automatically create a unique
number within the "id" field for all entries. You can the prefix the id
number with "NAME"+$id within php to achieve the above.

It really depends on what you want the serial number for, human readable
stuff or just passing on id within your site(s). You could use an md5()
hash of your number + some other variable to provide you with a more secure
id.

Nel.
Jul 17 '05 #2
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in message news:<jK*******************@wards.force9.net>...
"Paul Lamonby" <pa**@popimages.com> wrote in message
news:86**************************@posting.google.c om...
Hi,

i want to create a unique serial number to my Db entries. I thought
the best way would be to add the auto_increment primary key value to a
string, then insert it into a table field 'serial_num'.

$serial_num = "NAME000" . $auto_increment_value;

Is this possible in one function? Or do I have to insert all the other
data first, then get the last inserted id value and then update the
entry with the $serial_num variable?

Cheers


Hi Paul,

If you set one field type, lets call it "id", to an INT and set
auto_increment, primary, unique, this would automatically create a unique
number within the "id" field for all entries. You can the prefix the id
number with "NAME"+$id within php to achieve the above.

It really depends on what you want the serial number for, human readable
stuff or just passing on id within your site(s). You could use an md5()
hash of your number + some other variable to provide you with a more secure
id.

Nel.


Nel,

Cheers for the reply, I have got it sorted, but my post was more
concerned with the 'correct way' to do this.

I have my auto_increment, primary, unique 'id' field and my 'serial'
field.
What I am doing is INSERTing data into the Db, then retrieving the
mysql_insert_id(), then UPDATEing the same entry with the $serial
prefixed variable, $serial = "NAME000" . $id;

Is the the correct way to do it? Or can I retrieve the id in the same
INSERT statement? Or can mysql add a prefix to a auto_increment,
primary, unique field?

Paul
Jul 17 '05 #3
In article <86**************************@posting.google.com >, Paul Lamonby wrote:
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in message news:<jK*******************@wards.force9.net>...
What I am doing is INSERTing data into the Db, then retrieving the
mysql_insert_id(), then UPDATEing the same entry with the $serial
prefixed variable, $serial = "NAME000" . $id;


I presume it will work. But i don't see why you want to add a prefix to
the key? To me, it seems that that prefix is quite redundant.

I haven't had the time to check it out, but i think you might notice a
difference in speed (i know there is no theoretical base for this, but
it might to try it out in the real world) if you use an INT instead of
a CHAR for your primary key.

--
Tim Van Wassenhove <http://home.mysth.be/~timvw/contact.php>
Jul 17 '05 #4
Tim Van Wassenhove <eu**@pi.be> wrote in message news:<2h************@uni-berlin.de>...
In article <86**************************@posting.google.com >, Paul Lamonby wrote:
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in message news:<jK*******************@wards.force9.net>...
What I am doing is INSERTing data into the Db, then retrieving the
mysql_insert_id(), then UPDATEing the same entry with the $serial
prefixed variable, $serial = "NAME000" . $id;


I presume it will work. But i don't see why you want to add a prefix to
the key? To me, it seems that that prefix is quite redundant.

I haven't had the time to check it out, but i think you might notice a
difference in speed (i know there is no theoretical base for this, but
it might to try it out in the real world) if you use an INT instead of
a CHAR for your primary key.


Tim,

I know it seems strange, but I need this unique 'serial number' for
people to enter in via SMS to download an image from the server. I
could easily use the auto_increment primary key value, but people just
entering '1, 2, 3.. 34' as a serial number doesnt really have the same
kudos as a prefixed string, like IMAGE0023.

My post was wondering whether it is possible to set up a field in
mysql that auto_increments onto a string prefix, instead of having to
retrieve the id value and add it into another field, but it seems this
is not possible, so i have opted to retrieve the value and add it
manually.

Cheers
Jul 17 '05 #5
I noticed that Message-ID:
<86**************************@posting.google.com > from Paul Lamonby
contained the following:
My post was wondering whether it is possible to set up a field in
mysql that auto_increments onto a string prefix, instead of having to
retrieve the id value and add it into another field, but it seems this
is not possible, so i have opted to retrieve the value and add it
manually.


Wouldn't it be just as easy to get the system to ignore any prefix?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pjotr Wedersteers | last post by:
I have a table with quiz questions. Each question has a unique ID, based on an auto_increment field. Now I've discovered that with deleting rows from the table the deleted ID's are not reissued....
4
by: jjliu | last post by:
i have created the following table: create table test (field1 varchar(100), id integer unsigned not null auto_increment, unique (field1), primary key (id)); When i try to insert some values by...
9
by: Bart Van der Donck | last post by:
Hello, The first column of my table is AUTO_INCREMENT. I fill my table with 5 records with a blanco value in their first field. The first column of my table will then hold the values 1,2,3,4,5...
0
by: Shailesh | last post by:
I made a MyISAM table on mysql 4.0.18 NT with auto_increment column started at 2147483646. The third row I insert fails as expected because the integer range is maxed out. However, if I delete...
2
by: hjyn | last post by:
Hi, how can I add char to auto_increment? For example, the auto_increment is for integer, I want to add a character at the front of that number. Ex: >create table abs (UserID INT(3) NOT NULL...
1
by: Phil Latio | last post by:
Newbie questions here... Reading the MySQL manual regarding InnoDB databases, can someone confirm that: 1. if the server is rebooted, AUTO_INCREMENT reverts back to 1? 2. what happens if the...
2
by: Swinky | last post by:
I hope someone can help...I feel like I'm walking in the dark without a flashlight (I'm NOT a programmer but have been called to task to do some work in Access that is above my head). I have...
5
by: akapsycho | last post by:
I've got an index field which stores id numbers which are created by auto_incrementing and assigning that value as the id. ive already emptied out the values a few times since I'm testing, but I...
3
by: Richnep | last post by:
Hi all, I have tabbed subforms where I need to copy one field value from one subform over to another subform. Although I can run an update query to accomplish this I would like to do it through...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.