Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 CoverYourASP --> Articles from database

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
35 active users
2094 visitors today
4771 pages today
(only part of today)
Tools I use

CoverYourASP
Copyright © 1999-2010 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

The CoverYourASP front page

When 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...

Featured sponsor
My favorite resources

Tiki Statues - Tiki Masks - Tiki Totems



New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!