Limit MySQL Results
I'm connecting to a database and pulling results by the date they were added and sorting them accordingly, along with name. This explains the following code:
PHP Code:
$result = mysql_query("SELECT * FROM standFields ORDER BY dateadded DESC, name ASC");
echo '<br /><span class="errMsg indent emSmall">Currently sorting by <i style="color:darkred;">date added</i></span><br />'."\n";
echo '<table cellpadding="5px" cellspacing="0px" class="tableBorder indent"><tr>'."\n";
unset($standFields['notes']);
foreach($standFields as $key => $value){ echo "<td><b>$value</b></td>";}
echo "\n".'</tr>'."\n";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo '<tr>';
foreach($standFields as $key => $value){
if($key == 'name'){ echo '<td><a href="dEdit.php?viewSN='.$row['sn'].'">'.$row['name'].'</a></td>';}
else if($key == 'tags'){ echo '<td><a href="dEdit.php?viewSN='.$row['sn'].'">'.$row['tags'].'</a></td>';}
else{ echo "<td>$row[$key]</td>";}
}
echo '</tr>';
}
echo '</table>';
My question is this: how can I alter that while loop to only include, say, the most recent 20 rows, rather than all of them? There are going to be a huge amount of rows and it'd be nice to limit how many are displayed as the most recently added. Thanks.
Thou com'st in such a questionable shape
Hamlet, Act 1, Scene 4
Bookmarks