Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    what do i use for this little project?

    I want to make a list of random facts. Then I'd like to put them in a file so that they can be randomly pulled up at any time through a website. I have a pretty good basis in HTML and that's about it. So basically it would just be a little tiny blurb that changes everytime you refresh the page OR that just changes each day. I'm not sure how exactly to do this, can someone point me in the right direction? Much appreciated, thank you.

    Tim

  • #2
    Regular Coder
    Join Date
    Apr 2007
    Location
    U.S.A
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts
    You would need a simple little php script for that.
    Here is a little program I made for my site. It will randomly generate a new item each time the page is loaded!
    EX:
    PHP Code:
    <?php
    switch (rand(1,4)){
        case 
    "1":
            echo 
    "html goes here. This is item 1";
            break;    
        case 
    "2":
            echo 
    "html goes here. This is item 2!";
            break;    
        case 
    "3";
             echo 
    "html goes here. This is item 3";
            break; 
        case 
    "4";
             echo
    "html goes here. This is item 4";
              break;
               
    }

    ?>
    You can place html code in between the parenthesis. If you want to add or subtract options simply repeat, or delete part of the pattern. also at the very top where it says rand then 1,4 those are the numbers it will generate. You must have it so that the numbers will generate your highest "case".
    EX:
    PHP Code:
    <?php
    switch (rand(1,5)){
        case 
    "1":
            echo 
    "html goes here. This is item 1";
            break;    
        case 
    "2":
            echo 
    "html goes here. This is item 2!";
            break;    
        case 
    "3";
             echo 
    "html goes here. This is item 3";
            break; 
        case 
    "4";
             echo
    "html goes here. This is item 4";
              break;
        case 
    "5";
             echo
    "html goes here. This is item 5";
              break;
               
    }

    ?>
    Noticed I had to change the numbers inside the rand function to correspond with the amount of cases I have.

    P.S. don't forget to change your site from .html to .php

  • #3
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the help!

    i really don't know any PHP(although my forum is PHP based) but you did a good job of explaining it, it doesn't look to complicated. im going to give it a try, thanks for the help. by the way i am making this as a little program/script to sell here and there for probably 5 bucks, just wanted to make sure you don't have a problem with me using this.

    thanks!

  • #4
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I took the code and put it in a notepad document and saved it as a php file then opened it up in the browser just to give it a try, it didn't display anything. (It'll get obvious the more I speak that I don't know what I'm doing) So then I tried enclosing the "your html goes here" with <p></p>'s around the text thinking maybe it needed some html tags. that didn't work at all, it just displayed the whole entire code through the browser window then. im sorry i have no idea how to use php, but im sure im missing something simple here, i thought maybe if just fill in the blanks it'd work, what am i forgetting?

  • #5
    Regular Coder
    Join Date
    Apr 2007
    Location
    U.S.A
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This worked on my site http://www.awsomejoe23.heliohost.org...switcheroo.php
    PHP Code:
    <html>
    <head>
    </head>
    <body>
    <?php
    switch (rand(1,5)){
        case 
    "1":
            echo 
    "html goes here. This is item 1";
            break;    
        case 
    "2":
            echo 
    "html goes here. This is item 2!";
            break;    
        case 
    "3";
             echo 
    "html goes here. This is item 3";
            break; 
        case 
    "4";
             echo
    "html goes here. This is item 4";
              break;
        case 
    "5";
             echo
    "html goes here. This is item 5";
              break;
               
    }

    ?> 
    </body>
    </html>
    Post your code so I can see any problems. and if you are doing it from your computer not on your server I don't think it will work as you don't have php installed. Make sure you try it on a server.


  •  

    Posting Permissions

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