Posted by purcaholic on 05/22/07 08:31
On 22 Mai, 09:42, java.i...@gmail.com wrote:
> how to fetch the last five records in mysql through php
You can use mysql_data_seek to move the internal row pointer to the
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('SELECT * 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_array($result)) {
$data[] = $row;
}
}
var_dump($data);
[/snap]
purcaholic
Navigation:
[Reply to this message]
|