Jump to content

Recommended Posts

Here is the code.

[code]    // Write players from team 1
    $handle = fopen("trades.txt", "a");
    $content = "$team1 send:\n";
    fwrite($handle, $content);
    if ($player1) {
        $sql = "SELECT * FROM batrating WHERE PID='$player1'";
        $query = mysql_query($sql);
        $a = mysql_fetch_array($query);
        $pos = $a['pos'];
        $fname = $a['firsname'];
        $lname = $a['lastname'];
        $content = "$pos $fname $lname\n";
        fwrite($handle, $content);
    } [/code]

I have opened the trades.txt and placed the cursor at the bottom and made it writeable. My question is this, is there any way for me to pen that text file and write the new data to the top of the text file without overwriting the data below it?

The script prints the players traded to the text file, and the way that it is right now it writes the newest trades at the bottom so you have to scroll down to see them. I want to be able to open the text file and see the newest trades at the top. Any help would be great.
I don't know too much about arrays, but I'm reading up on it right now. array_reverse and all that stuff.

I just went the easy route, dumped the contents to a variable and then open the file, truncate it, write the new data, then dump the contents back in at the bottom.

Seems to be working, and the file shouldn't ever get that big to pose any problems.

Thanks for the help and pointing me in that direction.
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.