TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,993
  • Total Topics: 21,324
  • Online today: 247
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 254
  • Total: 255
  • lurkalot

Stumped on a block

Started by aerojad, August 27, 2007, 06:10:24 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aerojad

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.

This website is proudly hosted on Crocweb Cloud Website Hosting.