fubarur Posted July 27, 2006 Share Posted July 27, 2006 Hello, new to php and trying to learn it all. I have a script that shows articles. But instead of showing all of them I would like to show only the last 5. Can someone please help me out?Code:[sub] <?phpob_start();// Grab article placement id$id = $_REQUEST['id'];// Validate article idif(!Ambiance_HTML_Form_Validation::test($id, '0123456789', true, 10)): $id = 2;else: $placement_type = $db->getOne(array('name'), 'article_placement_type', 'id=' . $id); if(!strlen($placement_type)): $id = 0; endif;endif;?><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!-- START ARTICLE INDEX --> <tr> <td class="font-smx-bold"background="<?=Environment::webroot()?>/images/spacer.gif"> The Latest R/C Articles </td> </tr> <tr> <td background="<?=Environment::webroot()?>/images/spacer.gif"><script>ws('1','5')</script></td> </tr><?phpif($id):?> <tr> <td colspan="3" background="<?=Environment::webroot()?>/images/spacer.gif"> <table width="100%" border="0" cellpadding="3" cellspacing="0"><?php $sql = 'SELECT article.id, article.title, article.last_modified, article.date_added FROM article ' . 'LEFT JOIN article_access_level ON article.id = article_access_level.article_id ' . 'LEFT JOIN article_placement ON article.id = article_placement.article_id ' . 'WHERE article_placement.placement_id = ' . $id . ' AND article_access_level.access_level_id = 1 ORDER BY article.date_added DESC'; $articles = $db->query($sql); while ($article = $articles->fetchRow(DB_FETCHMODE_ASSOC)):?> <tr> <td> <div class="font-med"> <img width="11" height="11" src="<?=Environment::webroot()?>/images/arrow_right.gif" /><a href="<?=Environment::webroot()?>/articles/feature.php?article-id=<?=$article['id']?>" title="<?=Environment::encode_char(strip_tags($article['title']))?>"><?=strip_tags($article['title'])?></a></div> <div class="font-sm"> <?=date('M j, Y', strtotime($article['date_added']))?></div> </td> </tr><?php endwhile; //$articles->free();?> </table> </td> </tr><?phpendif;?> <!-- END ARTICLE INDEX --> </table>[/sub] Link to comment https://forums.phpfreaks.com/topic/15840-php-script-help/ Share on other sites More sharing options...
Barand Posted July 27, 2006 Share Posted July 27, 2006 $query = "SELECT article.id, article.title, article.last_modified, article.date_added FROM article LEFT JOIN article_access_level ON article.id = article_access_level.article_id LEFT JOIN article_placement ON article.id = article_placement.article_id WHERE article_placement.placement_id = '$id' AND article_access_level.access_level_id = 1ORDER BY article.date_added DESCLIMIT 5"; Link to comment https://forums.phpfreaks.com/topic/15840-php-script-help/#findComment-64875 Share on other sites More sharing options...
fubarur Posted July 28, 2006 Author Share Posted July 28, 2006 Barand,Thank you ever so much! That had escaped my brain, I guess I was looking at too much code today!Thanks again! Link to comment https://forums.phpfreaks.com/topic/15840-php-script-help/#findComment-64905 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.