> Or, you could do two steps
>
> 1) retrieve the last inserted ID, with mysql_last_inserted_ID (or
> something like that).
>
> 2) then, all records with id(s) greater then the_last_id_number minus
> five.
>
> something like
>
> $most_recent = select mysql_last_id();
>
> select * from TABLE where id > '$most_recent - 5';
>
> ...or something to that effect. There's probably a more efficient way to
> do it, but this guarantees the most recent five.
A) This would only work immediately after an INSERT, which may or may not be
useful
B) Technically, this might not be the most recent 5 if *OTHER* inserts have
happened in between your call to mysql_insert_id() and the query for the
last 5 in a non-transaction situation. If you have transactions going on,
this can get a bit confusing, depending on what kind of transactions etc...
A final note: While I can't imaginge how/why/when it would change, I'm not
at all certain that an auto_increment ID field is really the best way to get
the most recent inserts from a dba point of view. I generally use a
time-stamp for that purpose, to be more explicit that I'm getting records
created most recently, rather than the coincidence of having the highest
IDs.
Actually, I guess if the project is small enough or if you're really
anticipating millions of records and don't need creation date for other
purposes, I'd go with the ID field after all.
--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]