SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
-
Apr 10, 2009, 21:46 #1
- Join Date
- Nov 2005
- Location
- Karachi - Pakistan
- Posts
- 1,134
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Help with this Pseudo Random Algorithm
Hello
I have a situation, where I added some links in the database with their IMPORTANCE from 1 to 10. (where 10 is HIGHEST).
Now, i have an Ad Rotator that picks the link randomly and present that.
BUT what I want is that if a link is given the HIGHER importance that should be presented more than once (on page loads). So For example :
Suppose there are 5 AD Links are stored. Ad no. 2 is given a higher importance.
User A visits PAGE and the PAGE shows AD No. 1
User B visits PAGE and the PAGE shows AD No. 2
User C visits PAGE and the PAGE shows AD No. 3
User D visits PAGE and the PAGE shows AD No. 4
User E visits PAGE and the PAGE shows AD No. 2
User F visits PAGE and the PAGE shows AD No. 5
User G visits PAGE and the PAGE shows AD No. 2
------------ a cycle of random links complete --- now it will start again
User H visits PAGE and the PAGE shows AD No. 2
User I visits PAGE and the PAGE shows AD No. 5
User J visits PAGE and the PAGE shows AD No. 1
User K visits PAGE and the PAGE shows AD No. 2
User L visits PAGE and the PAGE shows AD No. 3
User M visits PAGE and the PAGE shows AD No. 2
you can see that in picking the RANDOM links, AD No. 2 was shown multiple times.
Please help me how this can be achieved.
Thanks
Zeeshan Hashmi
-
Apr 10, 2009, 22:08 #2
- Join Date
- Jul 2008
- Posts
- 5,757
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:SELECT ad FROM ads ORDER BY importance * rand() LIMIT 1
This isn't the most efficient query though if the table were to get large. A really easy way around that(if needed) would be to fake randomness. Just generate the list of ad id's ahead of time, give them a sequence, and cycle through them.
-
Apr 11, 2009, 07:04 #3
- Join Date
- Nov 2005
- Location
- Karachi - Pakistan
- Posts
- 1,134
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks for your ideas !
I will use and will let you know the results !
-
Apr 18, 2009, 23:48 #4
- Join Date
- Nov 2005
- Location
- Karachi - Pakistan
- Posts
- 1,134
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No, the idea do not works.
Some one, please guide me how this can be done!
Thanks
Zeeshan
-
Apr 19, 2009, 07:58 #5
- Join Date
- Jul 2008
- Posts
- 5,757
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It does "work", although maybe I musunderstand what you want, or maybe you implemented it wrong.
-
Apr 19, 2009, 08:33 #6
higher importance? How much higher. 3 out of 10? 4 out of 10? If you have 5 ads, and ads 2 have higher importance, then randomize from 1-10. if it shows 6-10, then show ad number 2. So ad no 2 will show more than the other ads.
-
Apr 19, 2009, 11:24 #7
- Join Date
- Mar 2004
- Location
- Kenneth City, FL
- Posts
- 823
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Add an "impressions" column to the table.
Add an "importance" column to the table.
Select a random row where "impressions" > 0.
If there are no rows with impressions > 0 then update the table so that "impressions" column = the value of the rows "importance" column and select again.
Code:UPDATE table SET impressions = importance
A row with a higher importance is going to therefore have more impressions.
-
Apr 21, 2009, 21:53 #8
- Join Date
- Nov 2005
- Location
- Karachi - Pakistan
- Posts
- 1,134
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hummmm I like the idea of Impressions,
Thanks joebert !
Bookmarks