Re: Finding last entry in MySQL database
| From: | Justin French | Date: | Sat, 16 Nov 2002 01:50:31 +0000 |
| Subject: | Re: Finding last entry in MySQL database | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-124676@lists.php.net to get a copy of this message | ||
on 15/11/02 8:11 PM, Tim Thorburn (immortal@nwconx.net) wrote:
> 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
> 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.
To answer your question first, assuming you have an numeric, unique id
column, you would do something like
SELECT * FROM tablename ORDER BY id DESC LIMIT 1
BUT, it's *possible* that another row could be inserted before you get the
chance to check... the real key here (assuming you are using MySQL) is to
use mysql_insert_id().
Justin French
--------------------
http://Indent.com.au
Web Developent &
Graphic Design
--------------------