Hello, I would like to implement a 50/50 rotator that will switch between either a default value or one from a variable. So something like function getvalueid() { rand (50% of time) = x if x > 50 return default valueid if X < 50 return variable valueid } I assume I can call it by doing something like <? echo getvalueid() ?> ?? something like that? Any help appreciated Thanks, Ivan
<? function switch(){ $tmp=rand(1,100); $yourvalue=999; $myvalue=0; if ($tmp<50){ return $yourvalue; } else { return $myvalue; } } ?> Code (markup): not tested. call with: echo switch(); Code (markup):
I would say if you are thinking about using the script with adsense and have several ads on one page. You need to have the same pub ID on all ads that are displayed on one page. You can not have different PUB_ID on the same page. Just a reminder ! What you need to do (for several displays this is) $PUB_ID = switch(); goole_PUB = <? echo $PUB_ID;?> Etc to make sure you have the same on all ads
If you only need a 50/50 random: function flipcoin($value1="",$value2="") { if (rand(0,1)) { return($value1); } else { return($value2); } } Code (markup): Then, in your program: <?= flipcoin("firstvalue","secondvalue"); ?> Code (markup): -Zeras
Thanks for everyone's help. I am still learning PHP, so excuse my newbiness Anyway...here is what I am trying to do...I dont think I have it setup right and the logic is quite odd?! Trying to piece it together based on what the programmer left off doing. // Sets default to Admins ID or if there is a user ID then sets that into $publisher_id variable if(!ted123_db_num_rows($sql_test_query)){ $publisher_id = ADMIN_PUBLISHER_ID; }else{ $sql_test = guru21_db_fetch_array($sql_test_query); $publisher_id = $sql_test['ad_publisher_id']; } // This is probably a bit repetitive but essentially, after getting the publisher_id (either users or admins), it will randomly rotate it function flipcoin($value1="",$value2="") { if (rand(0,1)) { return($value1); } else { return($value2); } } // calls rotate function which returns the publiser id to display $publisher_id = flipcoin("$publisher_id","ADMIN_PUBLISHER_ID"); Code (markup): Thanks for everyones help thus far