Results 1 to 6 of 6

Thread: Random Quotes

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Random Quotes

    Hi,
    I came across this link: http://www.oxyscripts.com/view_tutorial.php?id=51

    for a random quote generator. But I have a couple questions:


    Question 1:
    Since this script uses an array, doesn't this mean all the elements in the array will eat up memory? So a list of say, 200 quotes using the array method is advisable or inadvisable?


    Question 2:
    I had another idea to do the same thing. I can create a txt file with all the quotes on separate lines. I can then use

    PHP Code:
    $fileget file("quotes.txt"); 
    and then choose an array element from fileget[] at random. So the question here is, if I use the $fileget method, does this too eat up as much memory as the other method?

    Question 3:
    What is the best method to do this?


    Thanks a bunch.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Random Quotes

    Originally posted by mendhak
    Question 3:
    What is the best method to do this?
    MySQL database. Otherwise, your second method would probably be best...although fileget() is not a function?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm not sure how much memory this would take up, or how slow it would be, but you can always try and find out:

    Code:
    $f = explode("\n", file('filename.txt'));
    echo $f[$randomNumber];
    And then kill the array right after you've used it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Thanks. I'll be sticking to method 1 then, since I don't know how to work with dbs in PHP.

    Btw, fileget was the name of the array.

    $fileget = file("quotes.txt");


    puts each line of quotes.txt into an element of the array fileget[].

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by mendhak
    Thanks. I'll be sticking to method 1 then, since I don't know how to work with dbs in PHP.

    Btw, fileget was the name of the array.

    $fileget = file("quotes.txt");


    puts each line of quotes.txt into an element of the array fileget[].
    Oh, I understand what you mean now. You didn't have the $ on there when you were talking about it.

    Then that method is going to take up the same amount of memory as just creating a hardcoded array. You're just going to load it in different ways.

    Working with databases is easy in PHP. Why not learn?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by The Hobo

    Working with databases is easy in PHP. Why not learn?
    Point me in the right direction, and I will.

    A link to a tut for that would be very helpful... I haven't really found many good ones.

Posting Permissions

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



Click Here to Expand Forum to Full Width