Counter Running off Databse

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
bobbyaa
Forum Newbie
Posts: 17
Joined: Wed Oct 13, 2004 4:54 pm

Counter Running off Databse

Post by bobbyaa »

Any ideas on how I can incorporate an object into all of the pages that displays the next available number from a database? The idea is that the end user needs to be able to see this number to give it out prior to typing the information into the form. Ideally, I would prefer that it automatically update when someone else changes it. Thanks in advance.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

SELECT MAX(foo) + 1 AS next FROM bar;

But i prefer to use autoincrement with mysql. I presume most rdbms will have a similar option
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Most databases have sequences. You can emulate them in MySQL with a table with a single record in a single INT column.
(#10850)
Post Reply