PHP random Page Display Tutuorial?

Discussion in 'PHP' started by brianwiz, Apr 9, 2008.

  1. #1
    Hello,

    I have searched google and havent found a working link. Can anyone point me in a direction.

    I know how random text and images work but i cannot see how to do a random page.

    The reason im asking is that when someone comes to my page I want to display a different crossword or wordsearch puzzle without manually updating it

    Any help would be wonderful.
     
    brianwiz, Apr 9, 2008 IP
  2. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #2
    just use order by rand() LIMIT 10 in your mysql query to pull 10 random records in your database. Pull the records from the recordset and display it.
     
    olddocks, Apr 9, 2008 IP
  3. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Do you want to show random pages by using database or want to show it from directory?
     
    singh.ajit05, Apr 10, 2008 IP
  4. c4st

    c4st Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes, It would help if you provided us with more information about your page. If your trying to load a random html file I would use php's rand() function. If you ware trying to load random mysql results I would use mysql's rand function.
     
    c4st, Apr 10, 2008 IP
  5. brianwiz

    brianwiz Well-Known Member

    Messages:
    377
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #5
    If would be a random php page.

    Like for instances. I have a puzzles on playwordsearch.com

    One time a Sports Puzzle would load.. another time another puzzle.

    Hopefully not using MSQL to do this. But more then willing to
     
    brianwiz, Apr 13, 2008 IP
  6. extromaster

    extromaster Guest

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I am not sure what you need, do you want something like this?
    
    <?php
    $mypages = array("mypage1.html", "mypage2.html", "mypage3.html", "mypage4.html", "mypage5.html");
    
    $myrandompage = $mypages[mt_rand(0, count($mypages) -1)];
    
    echo $myrandompage;
    ?>
    
    Code (markup):
     
    extromaster, Apr 14, 2008 IP
  7. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes I think extromaster has submitted a script,,,.. in which it display random pages ...................It can work on PHP 4, PHP 5)
     
    singh.ajit05, Apr 15, 2008 IP
  8. brianwiz

    brianwiz Well-Known Member

    Messages:
    377
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #8
    Yes that is what im looking for displaying different pages.
     
    brianwiz, Apr 16, 2008 IP
  9. tpflanz

    tpflanz Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    For anyone who comes across this post now (2 years later), this is what I did to get the method listed above to work

    
    <?php
    $mypages = array("mypage1.html", "mypage2.html", "mypage3.html", "mypage4.html", "mypage5.html");
    
    $myrandompage = $mypages[mt_rand(0, count($mypages) -1)];
    
    include ($myrandompage);
    ?>
    
    Code (markup):
    Just needed to change the "include" a little
     
    tpflanz, Jul 17, 2010 IP