Jump to content

Recommended Posts

Hey,

    New to the whole PHP ting, so I am muddling through. Trying to write the output of 3 array values to a file with fwrite().  Right now I am getting a never ending loop outputting "264" all on the same line.

 

$fp = fopen('text.file', 'a');

$count = 1;
while ($count < $finish) {
        fwrite($fp, "$idarray[$count] $pwarray[$count] $rankarray[$count]");
        }
fclose($fp);

 

the values coming out of the arrays are:

 

idarray - 6 character integer

pwarray - 6 to 20 character alpha numeric

rankarray - 2 character integer

 

I am attempting to get a text file like:

 

123456 jf0mklf9 12

123456 jkfldjioenklf 12

123456 j40fGF4jnf99 12

etc....

 

Any help would be greatly appreciated.

 

Ryan

 

You dont seem too be incrementing the count variable? which means the value of $count will remain 1 and will cause the while loop to never end,

 

try the following edit

 

$fp = fopen('text.file', 'a');

$count = 1;
while ($count < $finish) {
        fwrite($fp, "$idarray[$count] $pwarray[$count] $rankarray[$count]");
        $count++; //Add 1 each time the loop is run.
        }
fclose($fp);

by adding $count++; too the while you are telling php too add 1 each time it's looped through, (it's the same as $count = $count+1;)

 

 

hope it helps

 

Stuie

Cool....thanks for the advice on incrementing the counter. I have only one more problem.....the data is now being outputted properly with the exception that it is coming out all on one line in the file rather than one set of values per line. eg:

 

rather than this:

 

123456 jf0mklf9 12

123456 jkfldjioenklf 12

123456 j40fGF4jnf99 12

 

I get this:

123456 jf0mklf9 12123456 jkfldjioenklf 12123456 j40fGF4jnf99 12

 

Any Suggestions?

 

Thanks in advance,

Ryan

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.