Closed Thread
Thread Tools Search this Thread
Unread 9th Feb 2012, 04:37 PM   #1
HyperActive Warrior
War Room Member
 
Alexander K's Avatar
 
Join Date: 2011
Location: HI
Posts: 323
Thanks: 40
Thanked 35 Times in 31 Posts
Default
How to code a PHP sequence array. Help.
Share on: 
fb share twitter share gplus share more share

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];
What I'm trying to achieve is an array that goes in order from 1, 2, 3, 4, and so on. Then starts back at 1 when it reaches the end. Basically, when someone clicks on a link it goes through the array and loads the next number. It goes up by clicks for everyone. Meaning Person A gets 1, Person B gets 2, and so on.

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.
Alexander K is offline  
Unread 9th Feb 2012, 09:35 PM   #2
HyperActive Warrior
War Room Member
 
drem's Avatar
 
Join Date: 2011
Posts: 369
Thanks: 113
Thanked 86 Times in 79 Posts
Default
Re: How to code a PHP sequence array. Help.
Share on: 
fb share twitter share gplus share more share

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
drem is offline  
The Following User Says Thank You to drem For This Useful Post:
Unread 9th Feb 2012, 09:38 PM   #3
HyperActive Warrior
War Room Member
 
drem's Avatar
 
Join Date: 2011
Posts: 369
Thanks: 113
Thanked 86 Times in 79 Posts
Default
Re: How to code a PHP sequence array. Help.
Share on: 
fb share twitter share gplus share more share

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
}
drem is offline  
The Following User Says Thank You to drem For This Useful Post:
Unread 10th Feb 2012, 09:11 AM   #4
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: How to code a PHP sequence array. Help.
Share on: 
fb share twitter share gplus share more share

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


Brandon Tanner is offline  
The Following User Says Thank You to Brandon Tanner For This Useful Post:
Unread 10th Feb 2012, 10:30 AM   #5
HyperActive Warrior
War Room Member
 
Alexander K's Avatar
 
Join Date: 2011
Location: HI
Posts: 323
Thanks: 40
Thanked 35 Times in 31 Posts
Default
Re: How to code a PHP sequence array. Help.
Share on: 
fb share twitter share gplus share more share

Thanks guys!

Going with Brandon's method. Testing it, seems like it'll work out great.

[YouDeserveWealth.com] - Create generational wealth with passive income.
Alexander K is offline  
Closed Thread


Bookmarks

Tags
array, code, php, sequence

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 05:51 PM.