| | #1 |
| HyperActive Warrior War Room Member Join Date: 2011 Location: HI
Posts: 323
Thanks: 40
Thanked 35 Times in 31 Posts
|
Been googling, and I haven't found how to do an array that goes in sequence. Found how to do a random one. Code: // Create the array $links = array(); // Populare the array $links[0] = "http://www.site.com/ads1.php"; $links[1] = "http://www.site.com/ads2.php"; $links[2] = "http://www.site.com/ads3.php"; // Count links $num = count($links); // Randomize order $random = rand(0, $num-1); // Print random link echo $links[$random]; I imagine this is fairly simple? Could someone show me or direct me to a website explaining? Thanks. |
| [YouDeserveWealth.com] - Create generational wealth with passive income.
| |
| |
| | #2 |
| HyperActive Warrior War Room Member Join Date: 2011
Posts: 369
Thanks: 113
Thanked 86 Times in 79 Posts
|
Well the biggest problem will be the array for all users, they are controlled by a per page load basis. If you held it in a database then loaded it, going at random or some 50/50 chance would be easy. To populate an array like you ask all you need to do is $links[] = 'site1'; $links[] = 'site2'; this will add it to the end of the array, in the order you are looking for. Ok just to elaborate a little array pushing is used in many languages, you can do the same with the array_push function http://php.net/manual/en/function.array-push.php array_push($links,"site url"); but it use to be faster to do the way I mentioned above, I haven't tested it in a long time tho. |
| Last edited on 9th Feb 2012 at 09:41 PM. Reason: array_push added | |
| |
| The Following User Says Thank You to drem For This Useful Post: |
| | #3 |
| HyperActive Warrior War Room Member Join Date: 2011
Posts: 369
Thanks: 113
Thanked 86 Times in 79 Posts
|
Then you would do a count check $arr_size = count($links); if($user_click_count > ($arr_size - 1)) { $user_click_count = 0; //reset to 0 since we were at the end } |
| |
| The Following User Says Thank You to drem For This Useful Post: |
| | #4 |
| Advanced Warrior War Room Member Join Date: 2006 Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
|
I wrote a simple php script a while back that rotates between 10 different links in sequence. You could easily modify it to use how every many links you want... http://www.warriorforum.com/programm...ml#post2968668 |
| | |
| |
| The Following User Says Thank You to Brandon Tanner For This Useful Post: |
| | #5 |
| HyperActive Warrior War Room Member Join Date: 2011 Location: HI
Posts: 323
Thanks: 40
Thanked 35 Times in 31 Posts
|
Thanks guys! Going with Brandon's method. Testing it, seems like it'll work out great. |
| [YouDeserveWealth.com] - Create generational wealth with passive income.
| |
| |
|
| Bookmarks |
| Tags |
| array, code, php, sequence |
| Thread Tools | Search this Thread |
| |