TinyPortal

Development => Support => Topic started by: aerojad on August 27, 2007, 06:10:24 AM

Title: Stumped on a block
Post by: aerojad on August 27, 2007, 06:10:24 AM
I was trying to make a top 20 most viewed articles block for my site.  I found some code that output the latest 10 articles and manipulated it to do what I wanted, or at least I thought.  Here is the code:

global $db_prefix, $scripturl;

$articles = db_query("
        SELECT art.date, art.author, art.subject, art.id, art.views
        FROM {$db_prefix}tp_articles AS art
                LEFT JOIN {$db_prefix}tp_variables AS var ON (var.id = art.category)
ORDER BY `views` DESC
        LIMIT 20", __FILE__,__LINE__);

if (mysql_fetch_assoc($articles) == 0)
        echo '
<tr>
<td>No Articles Submitted</td>
</tr>';
else
{
        while ($row = mysql_fetch_assoc($articles))
                echo '
Ã,· <a href="', $scripturl ,'?page=', $row['id'], '">', $row['subject'], '</a><br><font size="1">(', $row['views'], ' views)</font><br><br>
';


}

mysql_free_result($articles);


Works great, except it picks up articles 2 - 21, not 1 - 20.  Any idea why?  I'm using the latest TP and SMF as of this date.