Forum Moderators: open
At first, I have a site with 3 pages. I need 50% of visitors to go to page1, 25% of visitors go to page2, and 25% of visitors go to page3. Totally random, doesn't matter who you are, you just need to get bumped to one of those 3 pages.
Now the tricky part:
There will be more pages added every so often by the site owner, and the percentages will become dynamic. So theoretically, there could be 7 pages, with percentages of 40%, 10%, 10%, 10%, 10%, 10%, 10%
Using ASP & SQL Server, is there anyone with an efficent pseudo-idea?
I just need a push in the right direction.
When adding a page :get the fileCount of the files in the 'pages' folder
Dim an array - weightings (fileCount)
Assign the weighting percentages to each element of the array - not sure how your %ages work out here.
Read LastPageCount value from a text file - (initially set this value to 0)
if fileCount<>LastpageCount then
update the text file
insert a new row in the pageAdded table (pkDate/Time, NewNumberofPages)
loop 1 to filecount (n)
create records in a child table (pkAutonum, fkNewNumberofPages, pageNumber=n, hits=0, percentage = weightings(pageNumber) )
end loop
end
When hitting the homepage:
Read LastPageCount value from a text file
select the child records for NewNumberofPage=LastpageCount
multiply out the hits with the %ages.
write the values to an array and sort ascending
select the first elemenet - intPage
update NewNumberofPage where pageNumber=intPage set hits=++hits
Redirect to the page in the files collection index (intPage)
If the index on the files collection is unreliable, you will have to maintain a mapping of page id=page name in a database.
Good Luck!
Create a table in your SQL Server Database:
PageID INT
PageName VARCHAR
Percentage FLOAT
Total FLOAT
Fill the table with the following data:
PageID,PageName,Percentage,Total
1,Page1.asp,50,5
1,Page2.asp,25,3
1,Page3.asp,25,2
Use the following query:
SELECT PageID, PageName, Percentage, Total, Total/Percentage AS PercentageTotal FROM Pages ORDER BY PercentageTotal
Then increment the Total field of the first record in the set by 1. Run the query again and you will notice the positions change.
If you keep using this technique I think you'll keep an exact number of viewings to 50%/25%/25% although the method of displaying the pages is not random.
You could easily modify percentages and page names in the table making your solution dynamic and easy to impliment / change.
I used SQL to keep track of the total number of hits, and also keep the total number of hits each page has gotten. I made a big stored procedure that (among other things) divides the page hits by the total hits, finds the percentage, and returns back the page to direct to.
Thanks for everyone's help.