|
-
Jan 26th, 2003, 09:52 PM
#1
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.
-
Jan 27th, 2003, 04:29 PM
#2
Stuck in the 80s
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?
-
Jan 27th, 2003, 04:32 PM
#3
Stuck in the 80s
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.
-
Jan 28th, 2003, 12:54 AM
#4
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[].
-
Jan 28th, 2003, 11:45 AM
#5
Stuck in the 80s
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?
-
Jan 28th, 2003, 09:05 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|