Load last 3 items from database
Moderator: General Moderators
Load last 3 items from database
How would you load the last three items from a database using php?
Re: Load last 3 items from database
Code: Select all
SELECT whatever FROM tablename ORDER BY id DESC LIMIT 3Re: Load last 3 items from database
Code: Select all
$aryData = array();
$rsData = mysql_query('SELECT * FROM tblName ORDER BY fldName DESC LIMIT 3');
if ($rsData && mysql_num_rows($rsData) > 0) {
while ($aryData[] = mysql_fetch_assoc($rsData));
array_pop($aryData); // Last item will be FALSE, not a record
$aryData = array_reverse($aryData);
mysql_free_resouce($rsData);
}
unset($rsData);
// $aryData = Last three resultsCode: Select all
$aryData = array();
$rsData = mysql_query('SELECT * FROM tblName ORDER BY fldName DESC LIMIT 3');
if ($rsData) {
$intRows = mysql_num_rows($rsData)
if ($intRows>0) {
for($t=$intRows-1; $t>=0; $t--) {
$aryData[$t] = mysql_fetch_assoc($rsData);
}
mysql_free_resouce($rsData);
}
}
unset($rsData);
// $aryData = Last three resultsRe: Load last 3 items from database
Thanks guys, thats helps alot with this project 