Case Study: An Affiliate System With ASP - Generating links
(Page 5 of 7 )
The ShowLinks function displays a HTML page that contains three things: a form to generate links based on individual product ID's, a form to generate links based on product categories, and a list of banners and links that the user can simply copy and paste directly into their HTML pages.
The product links form The product links form allows the affiliates to enter the ID's of one or more products from the TechBuy website separated by commas. After that, they click on the "Build Links" button, which passes the ID's they entered to the CreateIDLinks ASP function.
CreateIDLinks takes the comma-seperated product ID's from the form and builds a SELECT query around them. The product ID, brand, title and image are taken from the products table and are displayed along with an affiliate link to that particular product:
txtProdIds = Request.Form("txtProdIds")
arrProds = split(txtProdIds, ",")
counter = 0
for counter = 0 to UBound(arrProds)
if IsNumeric(arrProds(counter)) then
strQuery = strQuery & "prodId = " & arrProds(counter) & " OR "
end if
next
'Get rid of the right at the end of the query
if Right(strQuery, 3) = "OR " then
strQuery = Left(strQuery, len(strQuery)-3)
end if
counter = 0
if strQuery <> "" then
strQuery = "SELECT DISTINCT prodId, brand+' '+prodTitle AS prod, image FROM Products WHERE " & strQuery & " AND Active = 1 ORDER BY prod ASC"
if objRS.State = 1 then objRS.Close
objRS.Open strQuery
... Each link has the tracking ID of the affiliate built into it. Here's a link for the AMD Athlon 2000+ XP, as shown above:
<a target="_blank" href="http://www.techbuy.com.au/prodredir.asp?prodId=17783&at=27">Buy the AMD Athlon 2000+ XP 1.67GHz 266FSB (no fan) at TechBuy</a> We will be looking at how the inbound tracking works later, so we will leave it for now.
The category links form The category links form works in much the same was as the product links form, however it build the links with tracking ID's to link directly back to one or more specific product categories.
The category links <form> tag looks like this:
<form name="frmAddCatLinks" action="affiliates.asp" method="post">
<input type="hidden" name="where" value="gencatlinks"> The hidden variable, where is used to tell affiliates.asp what to do when the form data is submitted to it. Haivng a value of gencatlinks makes the CreateCatLinks function execute.
CreateCatLinks takes the one/more selected categories from the Request collection variable called txtCatIds and builds a SELECT query, like this:
dim txtCatIds
txtCatIds = Request.Form("txtCatIds")
arrCats = split(txtCatIds, ",")
for counter = 0 to uBound(arrCats)
strQuery = strQuery & "catId = '" & trim(arrCats(counter)) & "' OR "
next
if right(strQuery, 3) = "OR " then
strQuery = left(strQuery, len(strQuery)-3)
end if
objRS.Open "SELECT catId, catName FROM Categories WHERE " & strQuery & " ORDER BY catName ASC" The resultant recordset, objRS, now contains a list of category ID's and category names from the categories table. These are output as links in textboxes and each one contains the affiliates tracking ID:
<textarea rows="3" cols="56" id="<%=counter%>"><a target="_blank" href="http://www.techbuy.com.au/category.asp?catId=<%=objRS.Fields(0).value%>&at=<%=intAffId%>">Buy <%=objRS.Fields(1).value%> at TechBuy</a></textarea> The links generated from the CreateCatLinks function look similar to those generated by the CreateIDLinks function:
<a target="_blank" href="http://www.techbuy.com.au/category.asp?catId=CLEARANCESTOCK&at=27">Buy *Clearance Stock* at TechBuy</a> Pre-made Banners Lastly, we have the premade banners. These are simply static HTML links which bring the visitor into TechBuy's front page. Here's one of the banners links:
<a target="_blank" href="http://www.techbuy.com.au/?at=27"><img alt="Click here to visit TechBuy" width="468" height="60" border="0" src="http://www.techbuy.com.au/tbaffban_1.gif"></a>Next: Tracking Links >>
More ASP Articles
More By Mitchell Harper