RE: [PHP] Getting the last record in a mysql table
| From: | Niklas Lampén | Date: | Fri, 18 Jan 2002 06:46:01 +0000 |
| Subject: | RE: [PHP] Getting the last record in a mysql table | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-81040@lists.php.net to get a copy of this message | ||
You're welcome.
Heh, why to make too hard. :)
Niklas
-----Original Message-----
From: hugh danaher [mailto:hdanaher@earthlink.net]
Sent: 18. tammikuuta 2002 8:40
To: niklas.lists@publico.fi
Subject: Re: [PHP] Getting the last record in a mysql table
Niklas,
Now that sounds like a solution!
Thanks,
Hugh
----- Original Message -----
From: Niklas Lampén <niklas.lists@publico.fi>
To: Php-General <php-general@lists.php.net>
Sent: Thursday, January 17, 2002 10:29 PM
Subject: RE: [PHP] Getting the last record in a mysql table
> If you have ID that is a incrementing number, you could just query
> like
> this:
> 'SELECT ID FROM MY_TABLE ORDER BY ID DESC, LIMIT 1'
>
> And there you have just one result, the last (biggest) ID number.
>
>
> Niklas
>
>
> -----Original Message-----
> From: hugh danaher [mailto:hdanaher@earthlink.net]
> Sent: 18. tammikuuta 2002 7:37
> To: Php-General
> Subject: [PHP] Getting the last record in a mysql table
>
>
> Help!
> I thought this would be easy but it ain't. What I want is the id
> number of the last record in a table. I've tried a number of
> variations to the following but am getting no where! Any help will be
> greatly appreciated. Hugh
>
>
> $results=mysql_query(" SELECT last_insert_id() FROM MY_TABLE ");
> $row=mysql_fetch_assoc($results); while
> ($row=mysql_fetch_row($results))
> {
> print "<tr>";
> foreach($row as $field)
> {
> if ($field=="")
> {
> $field=" ";
> }
> print "<td
> align=center><h5>".$field."</h5></td>";
> }
> print "</tr>";
> }
> print "</table></td></tr></table>";
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net To
> contact the list administrators, e-mail: php-list-admin@lists.php.net
>