[UPHPU] Sequentially number records with php/mysql

Brent Wilkinson brent at air2data.com
Wed Nov 10 11:09:22 MST 2004


Well you could do it this way.

function getNextUserId()
{
 $result = mysql_query("select max(user_id) from user") or die("Unable to
get next user id");
 $id = mysql_result($result, 0) + 1;
 return $id;
}

This is clunky though and the autoincrement way is the best and easiest way
to do it. I would also probably just add a extra field in the db and mark a
order inactive or deleted instead of actually deleting it.

Brent Wilkinson
Tech Manager
Air2Data
(866)-779-8585
(801)-510-7474

-----Original Message-----
From: Ashley Oviatt [mailto:ashovi at qwest.net] 
Sent: Wednesday, November 10, 2004 11:04 AM
To: Brent Wilkinson
Subject: Re: [UPHPU] Sequentially number records with php/mysql

Yeah, I already have it doing that, I was just wondering if there was a way
without the db to do it. This looks like the best way though.

Ash


Brent Wilkinson wrote:

> Autoincrement is the way to go
> 
> Sample line
> 
> alter table <table> add <column> int(11) not null auto_increment, add 
> primary key (<column>);
> 
> 
> Brent Wilkinson
> Tech Manager
> Air2Data
> (866)-779-8585
> (801)-510-7474
> 
> -----Original Message-----
> From: uphpu-bounces at uphpu.org [mailto:uphpu-bounces at uphpu.org] On 
> Behalf Of Wade Preston Shearer
> Sent: Wednesday, November 10, 2004 10:54 AM
> To: uphpu at uphpu.org
> Subject: Re: [UPHPU] Sequentially number records with php/mysql
> 
> 
>>I'm setting up a way for people to order business cards from our 
>>company.
>>
>>I have it all finished, but right now I'm just using random #'s to 
>>give them a job#. What's the easiest way to give them a sequential job 
>>number? I don't want a database full of unfulfilled orders, but I'm 
>>guessing that making a record in the db for each new customer is the 
>>way to go, and then delete the record if the person doesn't order, 
>>right?
>>
>>Anyway, just wanted to knwo what you guys thought.
> 
> 
> You can have the database automatically increment and assign a unique 
> ID to each new record.
> 
> For example, in MySQL, you can set a column to do this with something 
> like...
> 
> 	pid int unsigned auto_increment primary key,
> 
> 
> 
> 
> 
> _______________________________________________
> 
> UPHPU mailing list
> UPHPU at uphpu.org
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net
> 
> Sponsored by hostinginferno.com!
> 
> 






More information about the UPHPU mailing list