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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.