Results 1 to 3 of 3

Thread: Single Selection from PHP File

  1. #1
    Join Date
    Jun 2005
    Location
    Canada
    Posts
    68
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Single Selection from PHP File

    I am attempting to set up a separate php file that will allow me to randomly pull one line for placement into a page. I have tried the following "array" but I can only get it down to 2 lines. I am beginning to understand php now a little better and I have tried finding the answer in the PHP site only to go cross-eyed. Any direction here would be a big help.

    Current PHP code:

    <?php
    srand((float) microtime() * 10000000);
    $input = array(
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    '<a target="_blank" href="" title="">XXX</a><br>',
    );
    $rand_keys = array_rand($input, 2);
    echo $input[$rand_keys[0]] . "\n";
    echo $input[$rand_keys[1]] . "\n";
    ?>

    The link to pull it is standard
    <?php include("directorylist.php"); ?>

    Many thanks
    D

  2. #2
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    Should be this:
    PHP Code:
    $rand_key array_rand($input);
    echo 
    $input[$rand_key] . "\n"
    $rand_key isn't an array when you're only calling one item.

  3. The Following User Says Thank You to techietim For This Useful Post:

    Diversions (09-07-2008)

  4. #3
    Join Date
    Jun 2005
    Location
    Canada
    Posts
    68
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Makes perfect sense when someone explains it. Thank you so much for the help techietim it works a charm and solves the remaining immediate problem.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •