473,289 Members | 2,089 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,289 software developers and data experts.

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 3051
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.