Pass Random String Of Data Into Web Element With The Use Of A Next Button

Discussion in 'PHP' started by timallard, Aug 2, 2008.

  1. #1
    Hello,

    I want to implement a very simple element to my website.
    I think PHP would be the best way. I have programmed many things in PHP before, but for this project I think I am over complicating things.

    What I would like to do is have a webpage that has a next and previous arrow, that on each click randomly selects a "fact" or "tip" from an array, and have it take the place of a previous "fact or "tip".

    I was thinking that it each item would be in an iframe and they would just load in the window linking to one another, but that is to much work for something that can be accomplished easily in PHP,...im just suck on getting started.

    My main goal is to have it indexed in search engines the best way possible.

    Once again just a simple left and right arrow, that generates a random fact from my array that a user can get a new fact on click.

    I dont even think there is a need for a previous button, only a next.

    Any ideas on where I can start from?
    Also -I would like to avoid a database at this point. There are not many facts. Maybe 30 at most.

    All help is greatly appreciated.
    Thanks,
    -Tim
     
    timallard, Aug 2, 2008 IP
  2. Hallent

    Hallent Peon

    Messages:
    65
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    $facts[] = "fact 1";
    $facts[] = "fact 2";
    $facts[] = "fact 3";
    echo $fact[array_rand($facts,1)];
    echo '<a href="'.$_SERVER['PHP_SELF'].'">Next</a>
    ?>
    take a look at php.net/array and php.net/array_rand for information about what i did...
     
    Hallent, Aug 2, 2008 IP
  3. Hallent

    Hallent Peon

    Messages:
    65
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    or as you said you would like to have them indexed in search engines you could do this:

    <?php
    $facts[] = "fact 1";
    $facts[] = "fact 2";
    if (isset($_GET['fact_id'])) {
    $fact_id = (int)$_GET['fact_id'];
    } else {
    $fact_id = array_rand($facts,1);
    }
    echo $facts[$fact_id];
    echo '<a href="'.$_SERVER['PHP_SELF'].'?=fact_id='.array_rand($facts,1).'">Next</a>';
    ?>
     
    Hallent, Aug 2, 2008 IP
    timallard likes this.
  4. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #4
    Thank you very much. +REP
     
    timallard, Aug 2, 2008 IP
  5. Hallent

    Hallent Peon

    Messages:
    65
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    np if you have any questions let me know
     
    Hallent, Aug 2, 2008 IP