| View previous topic :: View next topic |
| Author |
Message |
Localhost I post too much
Reputation: 0
Joined: 28 Apr 2007 Posts: 3402
|
Posted: Sun May 04, 2008 4:43 pm Post subject: [PHP/MySQL] |
|
|
Well i want to know how i can set a unique ID to each input into the database...
For example, the first input is 1, the second is 2, and so on and so on... Thanks
_________________
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Sun May 04, 2008 5:15 pm Post subject: |
|
|
I'm not sure what you mean, but:
Let's say there's a table like that:
| Code: |
ID: NAME:
__________________________
1 rEakW0n
2 lolhax |
And you want that the query does take the next ID by itself?
So if someone creates the next entry that it takes ID=3 ?
If so, there's a simple MySQL query for that:
| Code: | | SELECT MAX(ID) AS total FROM <table> |
Just take the result of 'total'+1 then.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun May 04, 2008 5:27 pm Post subject: |
|
|
You can set table variables to auto-increment as well which will handle the values for you.
_________________
- Retired. |
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Sun May 04, 2008 5:48 pm Post subject: |
|
|
| Can you not just set a primary key for this?
|
|
| Back to top |
|
 |
Localhost I post too much
Reputation: 0
Joined: 28 Apr 2007 Posts: 3402
|
Posted: Sun May 04, 2008 8:45 pm Post subject: |
|
|
ah yes i did auto-inc.
Thanks
_________________
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Mon May 05, 2008 4:19 am Post subject: |
|
|
| noz3001 wrote: | | Can you not just set a primary key for this? |
Yea, but primary-key will just avoid a double entry of a certain value in a field (or more).
I didn't know about auto-increase yet thanks
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Mon May 05, 2008 12:23 pm Post subject: |
|
|
| rEakW0n wrote: | | noz3001 wrote: | | Can you not just set a primary key for this? |
Yea, but primary-key will just avoid a double entry of a certain value in a field (or more).
I didn't know about auto-increase yet thanks |
Primary Keys have always auto incremented when i've use them on the ID attribute.
|
|
| Back to top |
|
 |
|