11 line random quote system

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • orbstra@gmail.com

    #1

    11 line random quote system

    <?php

    //Variables
    //Quotes
    $quote[0] = "'If at first you don't succeed; call it version 1.0' -
    T-Shirt";
    $quote[1] = "Microsoft: 'You`ve got questions. We've got dancing
    paperclips.' - Unknown";
    $quote[2] = "I would love to change the world, but they won't give
    me the source code!' - Unknown";
    //Random Number
    $rndNum = rand(1,3);
    //Pring Random Quote
    echo $quote[rndNum];
    ?>


    Why does this not do anything!? Please help asap!

    -vas

  • Andy Hassall

    #2
    Re: 11 line random quote system

    On 22 Jul 2006 13:11:18 -0700, "orbstra@gmail. com" <orbstra@gmail. comwrote:
    > echo $quote[rndNum];
    >
    Why does this not do anything!? Please help asap!
    Look at http://uk2.php.net/error_reporting

    Turn up your error reporting level to maximum. PHP will then tell you why. The
    code above will raise a warning message.

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Noodle

      #3
      Re: 11 line random quote system


      orbstra@gmail.c om wrote:
      <?php
      >
      //Variables
      //Quotes
      $quote[0] = "'If at first you don't succeed; call it version 1.0' -
      T-Shirt";
      $quote[1] = "Microsoft: 'You`ve got questions. We've got dancing
      paperclips.' - Unknown";
      $quote[2] = "I would love to change the world, but they won't give
      me the source code!' - Unknown";
      //Random Number
      $rndNum = rand(1,3);
      //Pring Random Quote
      echo $quote[rndNum];
      ?>
      >
      >
      Why does this not do anything!? Please help asap!
      >
      -vas
      This will produce a random quote from an array...

      <?php
      //Where $quote is a string array
      echo $quote[array_rand($quo te)];
      ?>

      Comment

      • Noodle

        #4
        Re: 11 line random quote system


        orbstra@gmail.c om wrote:
        <?php
        >
        //Variables
        //Quotes
        $quote[0] = "'If at first you don't succeed; call it version 1.0' -
        T-Shirt";
        $quote[1] = "Microsoft: 'You`ve got questions. We've got dancing
        paperclips.' - Unknown";
        $quote[2] = "I would love to change the world, but they won't give
        me the source code!' - Unknown";
        //Random Number
        $rndNum = rand(1,3);
        //Pring Random Quote
        echo $quote[rndNum];
        ?>
        >
        >
        Why does this not do anything!? Please help asap!
        >
        -vas
        Also, here is what was wrong with your code...

        <?php
        //Variables
        //Quotes
        $quote[0] = "'If at first you don't succeed; call it
        version 1.0' - T-Shirt";
        $quote[1] = "Microsoft: 'You`ve got questions. We've
        got dancing paperclips.' - Unknown";
        $quote[2] = "I would love to change the world, but they
        won't give me the source code!' - Unknown";

        //Random Number
        $rndNum = rand(0,2); //The range should be from 0, 2
        not 1, 3
        //Pring Random Quote
        echo $quote[$rndNum]; //Left the $ off rndNum

        ?>

        Comment

        • boclair

          #5
          Re: 11 line random quote system

          Noodle wrote:
          orbstra@gmail.c om wrote:
          ><?php
          >>
          > //Variables
          > //Quotes
          > $quote[0] = "'If at first you don't succeed; call it version 1.0' -
          >T-Shirt";
          > $quote[1] = "Microsoft: 'You`ve got questions. We've got dancing
          >paperclips.' - Unknown";
          > $quote[2] = "I would love to change the world, but they won't give
          >me the source code!' - Unknown";
          > //Random Number
          > $rndNum = rand(1,3);
          > //Pring Random Quote
          > echo $quote[rndNum];
          > ?>
          >>
          >>
          > Why does this not do anything!? Please help asap!
          >>
          >-vas
          >
          This will produce a random quote from an array...
          >
          <?php
          //Where $quote is a string array
          echo $quote[array_rand($quo te)];
          ?>
          Wrong idea. Not integers.

          Try shuffle($quotes );

          echo $quote[0];

          Louise

          Comment

          Working...