Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: PHP Noob

  1. #1
    Join Date
    Dec 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow PHP Noob

    Hey,

    I'v been working with html and javascript for a while but when it comes to php i really suck,I was wondering if anyone had a script to display random text,description & link,I have a small movie review site and I wanted to have a table that displays a new movie everytime you reload the page,with a small ss of the the movies,small description and link to the big description. thank you for the support

    kind regards

    Mav

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The php for this is easy. the issue is getting the information.
    Would you store it in a database (best idea)? text file? Directly within the php code (worst idea)?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Dec 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    since i'm planning on iframing that page i think directly on the script would be easier.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It would create a really bulky page, and be limited later, especially for changing the values later on.
    It is a bit easier to code... might work for your purposes. Integrating with a database or maybe text file could help you later on... something to think about later.

    Basically... you could do something like this:
    PHP Code:
    Put this at the top of your page:
    <?php
    $array
    [0] = "this is a quote";
    $array[1] = "something else";
    //add as many as you want, increasing the number each time.
    $n rand (01); //Change the "1" to the highest value above.
    ?>

    This outputs the quote.
    Put it where you want the quote to go on your page:
    <?php
    echo $array[$n];
    ?>
    The top part assigns values to an array then chooses a random number, assigning it to $n.
    The bottom part takes that $n value and chooses the corresponding part of the array.
    If you need more than just the quotes, you can use more than one array, assigning in the same exact way, just using something different than "array" in $array[0]. Like $quote[0], etc.
    Then, when displaying them, just display all the variables there.

    Note: Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.
    that is from php.net. If you happen to be using a php version earlier than 4.2, you WILL need to seed the random number generator.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <?php
      $quote = array(
        "Quote one",
        "Quote two",
        "Quote three"
      );
      $quote = $quote[rand(0, count($quote) - 1)];
    ?>
    
    ...
    
    <?php echo($quote); ?>
    ... would be a more elegant way to do it, I think.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Indeed. I was going for simple, but that's much easier to manage. Good call.

    Additionally, I figured my way taught what going on a little better, in hopes that maverick would learn php
    But... now he's got two example, so that's better anyway, right?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Lol, you may be right with the latter
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Sure, but either way.
    (And, your example teaches me, so it's win-win-win )
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Dec 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thats for the help guys,so how would the text document script gets abouts?

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Text document script?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •