In this project we are going to look at how we might choose to handle the automatic selection of advertisements to be displayed on our web site. Not only how this can be done for static (non-search result) pages, but also dynamic (search result) pages. During the tutorial we will be discussing mostly the method of implementation. For more a more detailed view of exactly how our results were achieved you should look at the files supplied.
First, let's look at the objectives we're trying to achieve:
1) Advertisements should be automatically placed on our pages, with a
minimal amount of data entry or page modification.
2) On pages where the results of a search are shown, the advertisements shown should be tailored to match the search criteria. This allows more market penetration because only relevant advertisements are seen at any given time.
3) Search criteria used to select advertisements should use, as much as possible, the original SQL WHERE and ORDER BY clauses as the original search; reducing the amount of extra work required to implement this feature.
4) Advertisements and their selection criteria should be easily enabled/disabled as necessary. This is for those pesky people who don't pay their advertising space bills.
As always, there are things to be set up on the server for the example code to work. Once the files are uploaded, the System DSN should be created as "Advertisements" which could be changed to something else with appropriate editing. Also any locations where the include files are used should be corrected with the path the files were placed. And finally, if you are going to use the dynamic selection feature, you will need to update several locations with the necessary fields. More on that part later.
As far as the modification of your existing pages goes, that is
extremely easy. All you need to do is to add the appropriate include
advertisement.inc on static pages and
advertisement1.inc on dynamic pages. Remember that what we
classify as a static page is one that doesn't contain the result of a search
done by SQL Query.
As with a project of this nature, there are some mandatory changes to the include files. Both include files will need to be adjusted to output the advertisements so that they properly complete your pages as you have formatted them.
Even more extensive changes are required if you plan to use
advertisement1.inc. In this case, you will also have to make
sure that you pass a copy of the SQL string used to do your data selection so
that it can be used to select the advertisements. Inside
advertisement1.inc you will find comments where there are
necessary changes for this purpose. You will also note that changes are also
savecriteria.asp when you add
the appropriate fields to the Criteria table.
In order for your existing queries to work, you will need to add the fields to the Criteria table with the same field names that you would normally retrieve your data from. They should also contain the same data as you would normally retrieve. If you don't mind writing an extra SQL WHERE and possibly ORDER BY clause, you could use any field names that you wanted. Although it's possible to alias the field names, it is much easier to just use the names that you're already used to.
Any details about how the guts of this project works is available by looking at the source files. Happy programming!
This ZIP contains 2 include files for handling advertisement selection (one with extra criteria, one without), 1 MDB file containing the templates for the advertisement and criteria data, and 2 sample pages that use one of the templates. The ZIP also includes 1 HTM and 7 ASP pages that are the starting point for maintaining the advertisement and criteria data.