Jump to content

Php script help


fubarur

Recommended Posts

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]
<?php
ob_start();

// Grab article placement id
$id = $_REQUEST['id'];

// Validate article id
if(!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>
<?php
if($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">&nbsp;&nbsp;<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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?=date('M j, Y', strtotime($article['date_added']))?></div>
                                                                                                                                </td>
                                                                                                                        </tr>
<?php
        endwhile;
        //$articles->free();
?>

                                                                                                                </table>
                                                                                                        </td>
                                                                                                </tr>
<?php
endif;
?>
                                                                                        <!-- END ARTICLE INDEX -->
                                                                                        </table>

[/sub]

Link to comment
https://forums.phpfreaks.com/topic/15840-php-script-help/
Share on other sites

$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 = 1
ORDER BY article.date_added DESC
LIMIT 5";
Link to comment
https://forums.phpfreaks.com/topic/15840-php-script-help/#findComment-64875
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.