| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Senior Member | is this the best way ? hi i am trying to create a simple adsense rotation script which would display the ads in a certain ratio if i have to distribute the ads in 50-50% ratio then i would follow this Code: <?php $rand = rand(1,2); if ($rand == 1) print 'adsense code 1'; elseif ($rand == 2) print 'adsense code 2; ?> then should i do it manually by using Code: rand(1,2,3,4,5,6,7,8,9,0) or is there any better and more efficient way to do this all? |
| |
| | #2 (permalink) | |
| NamePros Regular | Quote:
Code: $adsense['1']= "code here"; $adsense['2']= "code here"; $rand = rand(1,2); echo $adsense[$rand]; if you want percentages and want them precise you should use a database.
__________________ Joćo Fernandes Silva Selling : 19P.ORG - ARCADEHITS.ORG - AZIAN.NET - COREFANS.COM - CTUTORIALS.NET - DEDISEEK.COM - HITCHECK.COM - HOST15.COM - HOSTCUSTOMER.COM - LARGETIPS.COM - SCRIPTCANDY.COM - VISUALBOOK.NET - VOXVPS.COM / .NET - WALLPAPERSARENA.COM | |
| |
| | #3 (permalink) |
| NamePros Regular | Here's a function that returns 0 or 1 based on which side of a user-definable threshold the random number ends up on. Explanation after the code: PHP Code: So...if you call the function as such: PHP Code: If you want the opposite to happen, e.g. the SECOND ad code to come up only 30% of the time, just invert the threshold: PHP Code: ![]() PHP Code: |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |