Random quote help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JDJones

    Random quote help

    I'm using the following to generate a random quote on a PHP page and it
    works fine:

    <?php
    $quotes[] = 'quote #1';
    $quotes[] = 'quote #2';
    $quotes[] = 'quote #3';
    $quotes[] = 'etc...';

    srand ((double) microtime() * 1000000);
    $random_number = rand(0,count($q uotes)-1);

    echo ($quotes[$random_number]);
    ?>


    My question is how can I modify this so that it would show a single
    quote but only every 10th time the page was called? I searched Google to
    see if there was a premade script that would do this but all I could
    find were ones like I'm already using.

    Thanks.

  • Per Gustafsson

    #2
    Re: Random quote help

    JDJones wrote:[color=blue]
    > I'm using the following to generate a random quote on a PHP page and
    > it works fine:
    >
    > <?php
    > $quotes[] = 'quote #1';
    > $quotes[] = 'quote #2';
    > $quotes[] = 'quote #3';
    > $quotes[] = 'etc...';
    >
    > srand ((double) microtime() * 1000000);
    > $random_number = rand(0,count($q uotes)-1);
    >
    > echo ($quotes[$random_number]);[color=green]
    >>[/color]
    >
    >
    > My question is how can I modify this so that it would show a single
    > quote but only every 10th time the page was called? I searched Google
    > to see if there was a premade script that would do this but all I
    > could find were ones like I'm already using.[/color]

    If you want this random you can simply use rand(0,9) == 0 or so, if you
    want it to be exactly every 10th time you need to write to a text file
    or a database. A quite simple task using fopen(), fwrite(), fread() etc.


    Per Gustafsson

    --



    Comment

    • Randell D.

      #3
      Re: Random quote help


      "JDJones" <wvnh2@netscape .net> wrote in message
      news:besn37$dhd $1@slb3.atl.min dspring.net...[color=blue]
      > I'm using the following to generate a random quote on a PHP page and it
      > works fine:
      >
      > <?php
      > $quotes[] = 'quote #1';
      > $quotes[] = 'quote #2';
      > $quotes[] = 'quote #3';
      > $quotes[] = 'etc...';
      >
      > srand ((double) microtime() * 1000000);
      > $random_number = rand(0,count($q uotes)-1);
      >
      > echo ($quotes[$random_number]);
      > ?>
      >
      >
      > My question is how can I modify this so that it would show a single
      > quote but only every 10th time the page was called? I searched Google to
      > see if there was a premade script that would do this but all I could
      > find were ones like I'm already using.
      >
      > Thanks.
      >[/color]

      I suggest a cookie or session or keeping track in a file if you want it
      exactly every ten times - if you're not bothered too bothered, you could
      divide the hour by ten and if the current minute fits between one of two
      values, use that to make your selection - that way a page refresh would
      pretty much get you the same value unless the user kept refreshing for
      longer than six minutes...



      Comment

      Working...