ASP/.NET Web Hosting
* 3 Months FREE *
CLICK HERE!
 CoverYourASP --> Searching articles for hand-picked keywords, Part 4

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
87 active users
2660 visitors today
4755 pages today
how is this done?
Tools I use

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

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

Querying the database

Having created the sSQLSearch SQL statement, let's search the database and display the results.

// open database connection
DBInitConnection ( );

// use static cursor to get record count
oRecordSet.Open ( 'SELECT URL,ShortDescr FROM ArticlePages WHERE ' + sSQLSearch, oConnection, adOpenStatic );

if ( !oRecordSet.EOF )
{
   var nCount = oRecordSet.RecordCount;

   Out ( 'I found ' + nCount + ' results matching "' + sSearch + '".<p>' );

   while ( !oRecordSet.EOF )
   {
      var sURL = '' + oRecordSet ( 0 );
      var sShortDescr = '' + oRecordSet ( 1 );

      Out ( '<a href="' + sURL + '">' + sShortDescr + '</a><br>' );

      oRecordSet.moveNext ( );
   }

   // release connection asap
   DBReleaseConnection ( );
}

The DB..( ) functions and the oConnection/oRecordSet objects are all defined in my Database.asp SSI. The code above shows a typical recordset loop, where you keep calling moveNext( ) until you have looped through all the records and reach End Of File (EOF).

That's the search. The only hard part was reading all those pages again, and deciding what you guys want to search for. There is always room for improvement of course - here are some things that I have on the list:

• Allowing boolean expressions such as "(a OR b) AND (c or d)".
• Storing keywords that were searched for in database.
• Displaying common search expressions.

Featured sponsor
My favorite resources

Tiki Statues - Tiki Masks - Tiki Totems


CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!