The CoverYourASP front pageWhen CoverYourASP's front page was redesigned recently I moved all the links to my articles into the database. The source code for the front page became a lot simpler as a result (and hence maintainable), and much more flexible. For example, to display links to the articles sorted by popularity I could use the code below. DBGetRecords ( 'SELECT * FROM Articles ORDER BY Hits DESC;' );
while ( !oRecordSet.EOF )
{
// the short description of the article, as a hyperlink
Out ( '<br><b><a href="' + oRecordSet ( "URL" ) + '">' + oRecordSet ( "ShortDescr" ) + '</a></b>' );
// the long description of the article
Out ( '<br>' + oRecordSet ( "LongDescr" ) );
// the category
Out ( '<br><i>From <b>' + oRecordSet ( "Category" ) + '</b>, ' );
// date last updated
Out ( 'published ' + oRecordSet ( "UpdateDate" ) );
// number of times viewed
Out ( ', ' + oRecordSet ( "Hits" ) + ' views</i>' );
oRecordSet.MoveNext();
}
|
That's not my code incidentally, but it demonstrates the point. (You should't use SELECT *, instead use SELECT field1,field2..) Anyway, beefing up this code and moving it into a function simplifed the home page even more. I just pass in the title, how to sort the data and how many records to show, as below: // ========================================
// the what's new section - the last articles to be published
// ========================================
ShowArticles ( 'What\'s new? The articles I\'ve been working on recently...', nByDate, 3 );
// ========================================
// the what's popular section - the most popular articles
// ========================================
ShowArticles ( 'What\'s popular? Read what your peers think is most interesting!', nByHits, 5 );
// ========================================
// articles by category
// ========================================
ShowArticles ( 'Articles by category', nByCategory, 1000 );
|
Part 2: Administering the Articles table... |