tvance929 Posted March 4, 2009 Share Posted March 4, 2009 Im doing this: while(list($Name, $Score)=each($result)) { $newScore = $Name.", ".$Score."\n"; fwrite($Handle, $newScore); } I was hoping to see this in my text file: SGT_todd,12234 Joe,1234 Dude, 1111 Fred,232132 JaNE, 4325 But my fricking text looks like this!?!" Fred,232132 SGT_todd,12234JaNE, 4325 Joe,1234 Dude, 1111 ,,,, Anyone gimme any help??? Link to comment https://forums.phpfreaks.com/topic/147853-cant-get-a-write-inside-of-a-while-associative-array-to-work-right/ Share on other sites More sharing options...
tvance929 Posted March 4, 2009 Author Share Posted March 4, 2009 This is SORT of a problem of the way the data looked to me in notepad... I started opening this in Word and it looked better but it is still doing this one thing: LT._to66ad,33354 fred, 5454 GENE, 5454 todd, 4343 SGT_toad,3334 joe, 2343 mike, 333 **The problem is that the first and second elements are closer than all the others. I want to use this as a way to save high scores but I am afraid when I read this file with it's inconsistencies, it will mess up... any advice??? Link to comment https://forums.phpfreaks.com/topic/147853-cant-get-a-write-inside-of-a-while-associative-array-to-work-right/#findComment-776022 Share on other sites More sharing options...
tvance929 Posted March 4, 2009 Author Share Posted March 4, 2009 OK - further clarification... Ive now changed my write method to w+ ... everything is looking good except that the one score that I add to my array doesnt give me the line break. say I add Pvt Bird to the array and then try and do the for each I get this in my text file: PFC_bird,634LT._to66ad,33354 CPT_twwwerad,6334 fred, 5454 GENE, 5454 todd, 4343 COL_trerad,3334 SGT_toad,3334 joe, 2343 mike, 33 All the other scores give me the nice line break but the one I added to the array does not... here is more of my code to show you more what Im doing: if ($arrayCount < 10) { //Add new name and score to end $scoresArray[$finalName] = $score; //asort($scoresArray,SORT_NUMERIC); } elseif ($score > end($scoresArray)) { array_pop($scoresArray); $scoresArray[$finalName] = $score; } //Reverse order $result = array_reverse($scoresArray, true); $File = "aa.txt"; $Handle = fopen($File, 'w+'); while(list($Name, $Score)=each($result)) { $newScore = $Name.",".$Score; fwrite($Handle, $newScore); //echo $Name."--".$Score."<br/>"; } fclose($Handle); --------------------------------- Again this all works great now except for the one new score that I added to the array -- it prints out but does not give me a new line in my text file......???? Link to comment https://forums.phpfreaks.com/topic/147853-cant-get-a-write-inside-of-a-while-associative-array-to-work-right/#findComment-776059 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.