I'm trying to create a scoring system using flat file (I know, I'd prefer to use mysql too). I have managed to create enough so that the variables are pulled out of the game (username and score) and put into said text file. I can also output this text file in a formatted table. However i cannot get the scores to sort in any order - ideally i want descending. however this doesn't seem to. I know its probably a stupid mistake somewhere but i could do with a fresh pair of eyes to look over it. Just to stress, it MUST be flat file, cannot use any form of sql.
This is the code snippet that looks right to me, but obviously isn't as its not doing what i need it to do.
Without knowing what is actually in the file and what part of each line should drive the ordering, it's hard to know exactly how it should be sorted. Without that info, my best guess would be to use natsort() or natcasesort().
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Without knowing what is actually in the file and what part of each line should drive the ordering, it's hard to know exactly how it should be sorted. Without that info, my best guess would be to use natsort() or natcasesort(). ;
The text file looks like this at the moment:
13,test,15,test1,1,test2,
I have tried natsort() and again, no effect. I've hunted around for information everywhere and some people seem to suggest i should be able to sort as it is using natsort etc whereas others suggestions imply i should be placing this in an array of sorts. Just wondered if one of you guys could clarify. In all honesty i am at this point but well and truely out of my depth now..
Cheers
So, how is it supposed to sort: just on the first numeric value ("13" in your example)?
Or perhaps you should be reading it with fgetcsv() if you need to break it up into fields based on the commas?
Or maybe none of the above?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks