Re: Finding last entry in MySQL database

From: Date: Fri, 15 Nov 2002 10:25:15 +0000
Subject: Re: Finding last entry in MySQL database
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-124578@lists.php.net to get a copy of this message
At 11:11 15.11.2002, Tim Thorburn said: --------------------[snip]-------------------- >I'm creating a form which will allow individuals to add themselves to an >online database and ask if they'd like to upload a picture. I have the >form setup which allows the individuals to add themselves - currently it >asks if they have a picture to upload (a yes or no drop menu). On the From a UI guide - it would be better to present either a checkbox, or two radiobuttons, for a simple question like this. Basically: is it a yes or no - use a checkbox (checked=yes) is it two options - use radiobuttons >screen after the individual adds them self, I'd like to check the database >for the last entry (the one just made) and then see if the picture column >has a yes or a no stored. > >What I don't know is how to select the last entry in a database ... I'm >sure its something very simple, but with being up until 5am working on this >site - it's slipped by caffeine powered brain. Could be tricky and depends on your data layout. (a) you have an auto-increment ID value, then select * from mytable where id = (select max(id) from mytable) (b) you have a timestamp field, then select * from mytable where dt_entry = (select max(dt_entry) from mytable) Note that the timestamp solution could easily produce duplicates while the auto-increments do not. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#124578) next »