Make Revenue With Your Own Banner Management System - Listing the banners (Page 6 of 11 )
Believe it or not, we've overcome the hardest part of our coding! For this step, we want to create a list of banners in our rotation, and we also want to be able to delete a banner if we need to. Lets start by creating a simple ASP script that will show our banners in a table on a HTML page. The code for banner.asp (described below) is part of the support material for this article and can be downloaded from the last page.
set objComm = Server.CreateObject("ADODB.Command")
objComm.ActiveConnection = objConn
objComm.CommandType = adCmdText
In this part of our ASP script, we are introducing a new database object called a command object. A command object is used to parse commands to SQL server. These commands can either be stored procedures, text commands, commands held in files, etc. For our banner system, we're only interested in passing plain old text queries to SQL server. To do this, we set the CommandType parameter of our command object (objComm) to adCmdText, meaning this: "Any query that is passed to SQL server should be interpreted as plain text".
Through the command object, we get a list of all of our banners using a simple select query. The results for the query are stored in our recordset object (objRS). This is shown below:
objComm.CommandText = "select * from banners order by bannerName asc"
set objRS = objComm.Execute
Now that we have a list of rows in our recordset object, we can loop through each row, and display the data in our HTML table. We will display a link to delete the banner (explained later), the banners name, impression and click-thru numbers, and image. Remember to change the strBanner_Path variable to the directory where you saved your banners.
strBanner_Path = "c:\inetpub\wwwroot\banners"
while not objRS.EOF
If all goes well, you'll be presented with a list of banners in your database, just like the one shown below: