RE: [PHP] last ten from mysql?
| From: | Jason Stechschulte | Date: | Thu, 13 Jul 2000 13:52:41 +0000 |
| Subject: | RE: [PHP] last ten from mysql? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-6442@lists.php.net to get a copy of this message | ||
I don't think it would work because if you delete the second row, and insert
another record, mysql will insert the record into the place where the second
row was. If you have 50 rows, then the last inserted, which is in the
second row of the table, would not be one of the last 10. For example
1:mysql
2:php
3:perl
4:javascript
delete row 2.
1:mysql
3:perl
4:javascript
insert another row
1:mysql
5:c++
3:perl
4:javascript
If you were always wanting to get the last 2 rows, then num_rows - 2 would
not give you the starting point for the last 2 rows inserted. So I still
think you would have to use something along the lines of
select * from table order by number desc limit 2;
This query will give you
4:javascript
5:c++
The other query will give you
3:perl
4:javascript.
Just because you have an auto_increment column in your table, don't let
yourself fall into the trap of thinking that mysql will sort it for you. It
tries to reuse disk space as much as possible and will insert a new row into
an empty space into the table. If you want something sorted in a particular
order, you have to sort it.
Jason Stechschulte
jpstech@nc.edu
-----Original Message-----
From: John Coggeshall [mailto:someone@internetaddress.com]
Sent: Wednesday, July 12, 2000 9:43 PM
To: Jason Stechschulte; PHP - GENERAL
Subject: RE: [PHP] last ten from mysql?
> I could be wrong, but if you do much deleting and inserting of records in
> the database, neither of these will definitely give you the last 10
records.
I don't think that they were two separate methods. Basically what he was
doing was finding the total number of records returned (using num_rows),
subtracting 10 then using a SQL statement to start from $start and retrieve
10 records. Since $start was num_rows() - 10, I don't see how it wouldn't
work...
Maybe I'm wrong.
John
--
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