| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Oct 2006 Location: http://akshayjain.org
Posts: 2,830
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 Join Date: Oct 2005 Location: Portugal
Posts: 800
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
????: NamePros.com http://www.namepros.com/programming/327686-is-this-the-best-way.html 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 | ||||
| |
| | #3 (permalink) |
| NamePros Regular Join Date: May 2004 Location: NYC
Posts: 236
![]() ![]() ![]() | 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: |
| |