how to fetch the last five records in mysql through php
Fetching
Collapse
This topic is closed.
X
X
-
java.inet@gmail.comTags: None -
lnsoso
Re: Fetching
On 5ÔÂ22ÈÕ, ÏÂÎç3ʱ42·Ö, java.i...@gmail .com wrote:1. save all query results in array, and use array_slice() get lasthow to fetch the last five records in mysql through php
five records.
[php]
$a = range(0,100);
var_dump( array_slice($a, -5));
2. modify u SQL cmd "ORDER BY DESC limit 5".
so sorry , i can't express myself very well in english.
-
Geoff Berrow
Re: Fetching
Message-ID: <1179819759.465 987.216870@36g2 000prm.googlegr oups.comfrom
java.inet@gmail .com contained the following:
Define 'last'.>how to fetch the last five records in mysql through php
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Comment
-
purcaholic
Re: Fetching
On 22 Mai, 09:42, java.i...@gmail .com wrote:You can use mysql_data_seek to move the internal row pointer to thehow to fetch the last five records in mysql through php
desired position. After then using a mysql_fetch_*() function in a
while loop will iterate until the last position of the results.
Example:
[snip]
if (!$result = mysql_query('SE LECT * WHERE 1=1')) {
die('Invalid query: ' . mysql_error());
}
if ($num_rows = mysql_num_rows( $result)) {
mysql_data_seek ($result, $num_rows-5);
while ($row = mysql_fetch_arr ay($result)) {
$data[] = $row;
}
}
var_dump($data) ;
[/snap]
purcaholic
Comment
-
gosha bine
Re: Fetching
On 22.05.2007 09:42 java.inet@gmail .com wrote:The words "first" and "last" only make sense when you tell mysql how tohow to fetch the last five records in mysql through php
>
sort the records, and if you did, just replace ASC with DESC and you're
in business ;)
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Comment
-
lnsoso
Re: Fetching
On 5ÔÂ22ÈÕ, ÏÂÎç3ʱ42·Ö, java.i...@gmail .com wrote:1. save all query results in array, and use array_slice() get lasthow to fetch the last five records in mysql through php
five records.
[php]
$a = range(0,100);
var_dump( array_slice($a, -5));
2. modify u SQL cmd "ORDER BY DESC limit 5".
so sorry , i can't express myself very well in english.
Comment
-
Toby A Inkster
Re: Fetching
java.inet wrote:
Don't. Modify your SQL to only select the last five records.how to fetch the last five records in mysql through php
SELECT x.*
FROM (SELECT *
FROM table
ORDER BY sortorder DESC
LIMIT 5) x
ORDER BY x.sortorder
--
Toby A Inkster BSc (Hons) ARCS
Fast withdrawal casino UK 2025 – Play now & cash out instantly! Discover the top sites for rapid, secure payouts with no delays.
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
Comment
-
ELINTPimp
Re: Fetching
On May 22, 4:04 am, Toby A Inkster <usenet200...@t obyinkster.co.u k>
wrote:completely agree with Toby. I used the exact method when designing ajava.inet wrote:>how to fetch the last five records in mysql through php
Don't. Modify your SQL to only select the last five records.
>
SELECT x.*
FROM (SELECT *
FROM table
ORDER BY sortorder DESC
LIMIT 5) x
ORDER BY x.sortorder
>
--
Toby A Inkster BSc (Hons) ARCShttp://tobyinkster.co. uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
module that displayed a summary of the 5 most recent help desk tickets
on our network management home page. always try to query only what
you need from a database, anything more is just unnecessary overhead.
Comment
-
ELINTPimp
Re: Fetching
On May 22, 4:04 am, Toby A Inkster <usenet200...@t obyinkster.co.u k>
wrote:completely agree with Toby. I used the exact method when designing ajava.inet wrote:>how to fetch the last five records in mysql through php
Don't. Modify your SQL to only select the last five records.
>
SELECT x.*
FROM (SELECT *
FROM table
ORDER BY sortorder DESC
LIMIT 5) x
ORDER BY x.sortorder
>
--
Toby A Inkster BSc (Hons) ARCShttp://tobyinkster.co. uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
module that displayed a summary of the 5 most recent help desk tickets
on our network management home page. always try to query only what
you need from a database, anything more is just unnecessary overhead.
Comment
Comment