Page 1 of 1
Whats wrong with isset?
Posted: Mon Feb 10, 2003 6:29 pm
by Nik
while (isset($quote=file_diary[rand(0, count($file_diary)-1)]) && $i==0)
{
echo $quote;
$i++;
}
I just need a way to get a random line from one text file except blank lines...
My text is like this:
1
2
3
4
5
and so on...
Thanks!
Posted: Mon Feb 10, 2003 6:35 pm
by Zoram
well right off... if you have the && $i == 0 and you are incrementing $i++ at the end of your loop then it's only going to go through once...
try this... not sure if it'll work but...(this is only for printing them once you have them in an array...)
Code: Select all
for ( $i = 0; $i < count($file_diary); $i++) {
echo($file_diaryїrand(0,count($file_diary)-1)]);
}
but that won't keep it from display multiple copies of the same entry...
you'll need to lookup some file functions to get the file into the array.
Posted: Mon Feb 10, 2003 6:40 pm
by Nik
yes i only want to print out once! one single random line from the file!
Posted: Mon Feb 10, 2003 6:43 pm
by Zoram
then once you have the file put into the array you only need:
echo($file_diary[rand(0,count($file_diary)-1)]);
i'd help you with the file to array but i can't seem to get to the php website at the moment...