PHP Rotation help needed

Discussion in 'General Programming Chat' started by Siek, Mar 21, 2009.

  1. Siek

    Siek Regular Member

    Joined:
    Feb 4, 2008
    Messages:
    456
    Likes Received:
    294
    Code:
    $A_offers = array(); 
    $A_offers[1] = array("1","OFFER1"); 
    $A_offers[2] = array("2","OFFER2"); 
    $A_offers[3] = array("3","OFFER3); 
    $A_offers[4] = array("4","OFFER4"); 
    
    $myFile = "count.txt";
    
    $fh = @fopen($myFile, 'r');
    $offerNumber = @fread($fh, 5);
    @fclose($fh);
    
    if ($offerNumber >= count($A_offer)) {
        $offerNumber = 1;
    } else {
        $offerNumber = $offerNumber + 1;
    }
    
    $fh = fopen($myFile, 'w') or die("can't open file");
    $stringData = $offerNumber . "\n";
    fwrite($fh, $stringData);
    fclose($fh);
    
    $b = $A_offers[$offerNumber][0];
    $reward = $A_offers[$offerNumber][1];
    
    
    I have a count.txt file in my directory. Im not sure whats wrong with this coding, could i get some hlep?

    my $b is my rotation ID

    and my $reward is my dynamic text that is displayed depending on the b value.

    if anyone could help me out here that would awesome.... My offers don't seem to be rotating
     
  2. jimbobo2779

    jimbobo2779 Jr. VIP Jr. VIP

    Joined:
    Sep 17, 2008
    Messages:
    4,121
    Likes Received:
    2,991
    Occupation:
    Software Engineer
    Location:
    UK
    Home Page:
    Well for starters you are missing a " in your array for Offer3. You don't seem to have any item stored at array index 0.

    This could be where you are going wrong but to be honest its a bit late here and Im having trouble reading code. Is there any reason you haven't done a file_get_contents to a string and then split this string into an array to easily pull the output that way or done a shuffle on that array and pulled the item at an arbitrary array index.

    If I don't make much sense or you need some clarification to any of this just PM me. Id be happy to help you out further.

    Jim