multi arrays and fetching variables

Discussion in 'PHP' started by IamNed, Nov 3, 2010.

  1. #1
    lets say I have an external text file .txt with the following

    A1
    A2
    B1
    B2
    C1
    C2
    ..
    ..
    ..

    And I have multiple php pages. How would I fetch A1 on one page and A2 on another page? And then when you refresh the pages it fetches some other random pair like R1 R2?

    Is there a way to do this?
     
    IamNed, Nov 3, 2010 IP
  2. mikecampbell

    mikecampbell Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is the same person loading both the two pages where A1 and A2 appear?
     
    mikecampbell, Nov 3, 2010 IP
  3. IamNed

    IamNed Peon

    Messages:
    2,707
    Likes Received:
    276
    Best Answers:
    0
    Trophy Points:
    0
    #3
    actually I have a simpler question regarding pairs on one page

    this script keeps giving me an error. I'm trying to echo both array values and it wont work



     
    
    <?
    
    $array = array('eggs', 'bacon', 'football', 'baseball', 'ford', 'toyota'); 
    
    $rand_index = mt_rand(0, count($array) / 2 - 1) * 2; 
    
    echo $array[$rand_index] . " <br> " . $array[$rand_index + 1]; 
    
    ?>
    
    
    
    <?php echo "$array[$rand_index]"; ?><?php echo "$array[$rand_index+1]"; ?>
    PHP:
     
    IamNed, Nov 3, 2010 IP
  4. mikecampbell

    mikecampbell Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The code works fine when I try it, except for this part:
    
    <?php echo "$array[$rand_index+1]"; ?>
    PHP:
    Addition won't be evaluated like that in a string. Get rid of the double quotes.

    
    <?
    
    $array = array('eggs', 'bacon', 'football', 'baseball', 'ford', 'toyota');
    
    $rand_index = mt_rand(0, count($array) / 2 - 1) * 2;
    
    echo $array[$rand_index] . " <br> " . $array[$rand_index + 1];
    
    ?>
    
    
    
    <?php echo $array[$rand_index]; ?><?php echo $array[$rand_index+1]; ?>
    PHP:
     
    mikecampbell, Nov 3, 2010 IP
  5. sabaina

    sabaina Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    off the top of my head: you need a queue table with pairs that can be fetched at a given time along with their fetch status.
     
    sabaina, Nov 5, 2010 IP