Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 20,661 times

Contents

Related Categories

Searching articles for hand-picked keywords - Querying the database

cyasp

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.

 

Comments

  • Search Facility

    Posted by IanB on 05 Mar 2004

    I tried to run the code as is, but found an error with the following:

    sSearch = sSearch.replace ( /['"%]/g, '' );

    Do you not need to create an instance of the type RegExp in oredr to get the re...