<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <%Server.ScriptTimeout=200%> Neotropical Bird Club

Home | About NBC  | Join/rejoin NBC | Contact Us

Journals | Search | NeoNews | Events | Conservation Fund / Premios de Conservación | Awards Update | Corporate Members 
Editorial Guidelines | Advertise with NBC | Cotinga Index [1-10] [11-20] | Neotropical Birding Index [1-9] [10-11]
Neotropical Birding | Back Issues | Club Constitution | Online Donations

<% ' Declare our variables... always good practice! Dim strURL ' The URL of this page so the form will work ' no matter what this file is named. Dim cnnSearch ' ADO connection Dim rstSearch ' ADO recordset Dim strDBPath ' path to our Access database (*.mdb) file Dim strSQL ' The SQL Query we build on the fly Dim strSearch ' The text being looked for ' Retreive the URL of this page from Server Variables strURL = Request.ServerVariables("URL") ' Retreive the term being searched for. I'm doing it on ' the QS since that allows people to bookmark results. ' You could just as easily have used the form collection. strSearch = Request.QueryString("search") strSearch = Replace(strSearch, "'", "''") ' Since I'm doing this all in one page I need to see if anyone ' has searched for something. If they have we hit the DB. ' O/W I just show the search form and quit. %>

Search for Articles or Authors. (% returns all records)

[Try 'Colom' or 'Howe' for example]

<% If strSearch <> "" Then ' MapPath of virtual database file path to a physical path. ' If you want you could hard code a physical path here. strDBPath = Server.MapPath(".") strDBPath = "\\iis623\domains\n\neotropicalbirdclub.org\user\private\cotinga.mdb" 'strPath = Server.MapPath(".") 'Response.Write strPath & "
" 'strPath = "\\iis614\domains\b\birding-colombia.com\user\private\Tables.mdb" 'Response.write replace(replace(strPath, "htdocs", "private"),"guides","") ' Create an ADO Connection to connect to the sample database. ' We're using OLE DB but you could just as easily use ODBC or a DSN. Set cnnSearch = Server.CreateObject("ADODB.Connection") ' This line is for the Access sample database: cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";" ' We're actually using SQL Server so we use this line instead: 'cnnSearch.Open "Provider=SQLOLEDB;Data Source=;" _ '& "Initial Catalog=samples;User Id=samples;Password=password;" _ '& "Connect Timeout=15;Network Library=dbmssocn;" ' Build our query based on the input. strSQL = "SELECT * " _ & "FROM [Index] " _ & "WHERE ArticleTitle LIKE '%" & Replace(strSearch, "'", "''") & "%' " _ & "OR Author LIKE '%" & Replace(strSearch, "'", "''") & "%' " _ & "ORDER BY IssueID;" ' Execute our query using the connection object. It automatically ' creates and returns a recordset which we store in our variable. Set rstSearch = cnnSearch.Execute(strSQL) ' Display a table of the data in the recordset. We loop through the ' recordset displaying the fields from the table and using MoveNext ' to increment to the next record. We stop when we reach EOF. ' For fun I'm combining some fields and showwing you can do more then ' just spit out the data in the form it is in in the table. %> <% Do While Not rstSearch.EOF %> <% rstSearch.MoveNext Loop %>





<%= rstSearch.Fields("ArticleTitle").Value %>


">Cotinga <%= rstSearch.Fields("IssueID").Value %>

<% ' Close our recordset and connection and dispose of the objects rstSearch.Close Set rstSearch = Nothing cnnSearch.Close Set cnnSearch = Nothing End If %>

<% Function RandomImage(ImagesFolderPath, ImageFileTypes, ImageDescription) 'Declare variables Dim CompleteImagesFolderPath Dim FileSystemObject Dim ImageFolder Dim Files Dim i Dim ImageFiles Dim File Dim FileName Dim FileExtension Dim RandomNumber 'Find the complete path to image folder by using Server.MapPath CompleteImagesFolderPath = Server.MapPath("images/random/") 'CompleteImagesFolderPath = "\\iis623\domains\n\neotropicalbirdclub.org\user\htdocs\images\photos\" ImageFileTypes = "jpg" 'Create an instance of the FileSystemObject which allows ASP to 'access the file system Set FileSystemObject = Server.CreateObject("Scripting.FileSystemObject") 'Check that the folder containing the images exists If Not FileSystemObject.FolderExists(CompleteImagesFolderPath) Then RandomImage = "Error 0: Cannot find requested folder" Set FileSystemObject = nothing Exit Function End If 'Get the folder containing the images Set ImageFolder = FileSystemObject.GetFolder(CompleteImagesFolderPath) 'Get a list of all the files within the images folder Set Files = ImageFolder.Files 'Use a dictionary object to temporarily store the image file names i = 1 Set ImageFiles = Server.CreateObject("Scripting.Dictionary") 'Loop through the list of files within the images folder. 'If the file has a file extension that is in the list of 'file types specified in the ImageFileTypes function parameter, 'then add the file name to the ImageFiles dictionary object For Each File in Files FileName = File.Name FileExtension = Right(FileName, Len(FileName) - (InStrRev(FileName, "."))) If InStr(1,ImageFileTypes,FileExtension,vbTextCompare) > 0 then ImageFiles.Add i, FileName i = i + 1 End If Next 'Destroy objects that are no longer required Set ImageFolder = nothing Set Files = nothing Set FileSystemObject = nothing 'Initialise the random number generator Randomize ' Check that image file(s) have been found If ImageFiles.Count = 0 Then RandomImage = "Error 1: Requested folder does not contain any image files" Exit Function End If 'Generate a random number between 1 and the number of image files RandomNumber = Int((ImageFiles.Count) * Rnd + 1) 'Return a hyperlink to a random image file RandomImage = " & Chr(34) & ImageDescription & Chr(34) & " Set ImageFiles = nothing End Function %> <%Response.Write RandomImage("images/random/", "gif jpeg", "")%>


© Neotropical Bird Club. All rights reserved.
UK registered charity 1040130
UK Address: c/o The Lodge, Sandy, Bedfordshire, SG19 2DL, United Kingdom
USA Address: P.O. Box 55, Cape May Point, NJ 08212, USA