php-db | 2000121
Date: 12/15/00
- Next message: Matthew Ballard: "Re: [PHP-DB] Fetching (and displaying) the 3 newest items from MySQL"
- Previous message: Mattias Johansson: "[PHP-DB] Fetching (and displaying) the 3 newest items from MySQL"
- In reply to: Mattias Johansson: "[PHP-DB] Fetching (and displaying) the 3 newest items from MySQL"
- Next in thread: Matthew Ballard: "Re: [PHP-DB] Fetching (and displaying) the 3 newest items from MySQL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
When you are doing your SQL query, you can do something like this:
SELECT *
FROM mytable
WHERE
.
AND
.
.
ORDER BY id DESC
LIMIT 3
Substitute "id" with whatever you named your auto-increment column (and use
any WHERE and AND clauses that you feel you need as well). The "LIMIT 3"
clause will only return 3 rows in your query and the "ORDER BY id DESC"
clause will start with the highest id value.
HTH
Sam Masiello
System Analyst
Chek.Com
(716) 853-1362 x289
smasiello <email protected>
-----Original Message-----
From: Mattias Johansson [mailto:smart <email protected>]
Sent: Friday, December 15, 2000 3:35 PM
To: php-db <email protected>
Subject: [PHP-DB] Fetching (and displaying) the 3 newest items from MySQL
Hi, I'm a newbie in need of your great wisdom.
I need help on how to fetch the three most newly added items from a specific
table in a MySQL database. The records in the table are NOT dated, but they
do contain have an ID, that is highest for the most newly added item. So,
what I want to do is:
1. Take the table and order it with the highest ID first
2. And then take the first 3 items.
3. After that, I also need to display the 3 items, of course!
Can you please help me? I'm very new to PHP, but so far I'm very impressed
by it!
/Mattias
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe <email protected> For additional commands, e-mail: php-db-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe <email protected> For additional commands, e-mail: php-db-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Matthew Ballard: "Re: [PHP-DB] Fetching (and displaying) the 3 newest items from MySQL"
- Previous message: Mattias Johansson: "[PHP-DB] Fetching (and displaying) the 3 newest items from MySQL"
- In reply to: Mattias Johansson: "[PHP-DB] Fetching (and displaying) the 3 newest items from MySQL"
- Next in thread: Matthew Ballard: "Re: [PHP-DB] Fetching (and displaying) the 3 newest items from MySQL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

