Not sure how to help on this as I don’t know your table structure or
exactly what you are trying to do, but I generally find the way I
would set up a table that has an id as Primary Key would be to set it
to an ‘int’ and then select ‘auto increment’
This will automatically set the id as an entry is made, first entry
would be 1, second 2 etc. so you then have each entry with a unique id
that you can use to access data from that entry in that table (if you
need this?).
Then enter any other information you want in the table in columns
relative to the schema for your db.
For example:
id | address | other | other
1 | 12345 | ? | ?
2 | 12345 | ? | ?
3 | 17344 | ? | ?
This way ‘example above’ you have two entries for address/client 12345
so you can then pull the entries for that client.
The reason you get an error for duplicate entries is because you are
trying to make a duplicate entry, use something like PHPMyAdmin to
view the data from the database, it is an easy way of reading the
database structure and the data it contains and you can easily search/
test for data in any of the columns to match or whatever that you need
without writing out a script to do it.
If your id column has entries with a hyphen such as ‘12345-1’ then
that data would not be compatible with an ‘int’ field type. Personally
I would not use any hyphens in data unless it is in a piece of text, I
don’t really see the point, or at least not with anything I have ever
had the need to write. I tend to think of data in columns as
straightforward blocks of information, a digit, a number, a word, a
group of words/text or a path for example. Generally I would look at
something like ‘12345-1’ as two different items of data, which does
not mean is a bad way of stroing information. I often use several
peices of data in a column entry that is delimited and then explode
them into variables when the data is retreaived but this would be data
that I would never need to search for. Take your ‘12345-1’ as an
example: (I am not totally sure this is what you are doing but) two
entries with addresses/clients as ‘12345’ and two references to
entries ‘-1’ and ‘-2’, using two columns, one for the client or
address ‘12345’ and another for the id ‘1’ allows you to perform an
easy search for this data, having the id set to auto_increment then
knocks the id over 1 for each entry you make, so on entering the data
for the other columns ‘and not any id’ the id will automatically
increment by 1 for each entry.
If you need show the information somewhere as ‘12345-1’ as a reference
number then print out the number with a hyphen between the two
variables, again this is something I have done in the past and found
an easy way of doing that is to store the ‘-’ in a variable in a
config file and then when used the hyphen will show, if it needs to be
changed to ‘:’ then you just change the value of the variable in the
config file and it changes everywhere it is used.
HTH
On Feb 7, 2011, at 4:17 PM, DeltaDave wrote:
OK - probably a dumb question
I am working on setting up a DB with my ID field set as Primary Key
Currently I have the ID field type as varchar but the ‘order nos’
that I am using in this field I would like to take the format
12345-1, 12345-2 when there are 2 orders relating to 1 address.
(Only half a dozen of the total 100 or so will require this)
But when I try and change the DB entry for 12345-1 from PHP on a FW
webpage I get a MySQL error 1062 ‘Duplicate entry ‘12345-1’ for
key 1’ error message
I am assuming that the ‘-’ character is being ignored and that is
why I get the error.
What is the most suitable field type to use and if I change it on
the existing DB will it affect the entries there already?
David
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options