ASP/.NET Web Hosting
* 3 Months FREE *
CLICK HERE!
 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
137 active users
10188 visitors today
11021 pages today
how is this done?
ASP.NET Showcase
ASP.NET Graph and Chart Component with FREE developer version

ASP.NET Shopping Cart and E-commerce Control with FREE trial download

ASP.NET Web Hosting with free month and setup

$15 Domain Name Registration from .DNR.
As seen on these sites
Special thanks go to the sites that support me by publishing my articles.
See more

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

ASP.NET Blog
ASPRSS
ShawThing

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

Selling products online - read how James does it now



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

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


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...