Whats wrong with isset?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Whats wrong with isset?

Post 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!
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post 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++) &#123;
   echo($file_diary&#1111;rand(0,count($file_diary)-1)]);
&#125;
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.
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

yes i only want to print out once! one single random line from the file!
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post 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...
Post Reply