In an earlier 10-Minute Solution, "Making Dynamic Content Available via ASP", I showed you how to develop an application using Active Server Pages to produce WML. There are other applications of server-side programming (ASP) that output directly to WML. For example, in this Solution, I show you how to develop a rotating banner ad system for Wireless devices.
| |
|
Figure 1: A banner ad display
|
Figure 1 shows a possible way to display banner ads on a WAP site. This screen shot comes from the beta release of Nokia's new WAP toolkit. (You can give the wireless Web surfer an opportunity to click the banner ad by adding that functionality to the left soft key on the phone.)
For the purposes of this demonstration, let's assume I want to create an application that puts a banner ad at the top of any page that includes it. I'm going to be using VBScript to generate my ASP. To add scalability, I'm going to pull all the relevant information from a database, thereby making the generated content dynamic. I'll randomly select an entry from the database and then display that information. It's possible to "cycle" through ads, but for this demonstration I'm going to pull up one entry randomly. Each time the page loads, a new ad will be displayed.
Here's an overview of my imaginary database structure. A primary key, bannerid, is sequential in TBL_ADINFO, a table from the larger database. Other fields in that table are bannertext and bannerURL. Bannertext contains the actual text message of the banner ad and bannerURL includes a click-through link, if needed. I could also include a graphic, but for simplicity, I'll leave that out.
<%@Language=VBScript
' Defining a constant for the randomizer
MaxNoAds = 10
' Setting our content type
Response.ContentType = "text/vnd.wap.wml"
' Randomly selecting an entry from the database
Randomize(Cbyte(Left(Right(Time(),5),2)))
AdID=(Int((MaxNoAds-1+1) * Rnd + 1))
' Pulling information from the database
set objConn = Server.CreateObject("adodb.connection")
objConn.Open "dsn=adserver;uid=adserver"
sql = "SELECT * from TBL_ADINFO where bannerid = '" & AdID & "'"
set rsAd = objConn.Execute(sql)
' Displaying the WML content
%>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="bannerad" title="Ad">
<p>
<a href="<%=rsAd("bannerURL")%>"> <%=rsAd("bannertext")%>
</p>
</wml>
Now that I've created the guts of the system, I can go ahead and implement it. On every page that I want to have a banner ad, I simply do an include, as follows:
<!--- #include file="bannerad.asp" --->
Now I've got my banner ads!
Return to Get Help with Wireless Dev Page
Return to Main Get Help Page