The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Loading Contents of a File -> Sorting everything?
You guys have helped me countless times before.. and yet again, I come to you for a little kick in the right direction.
Let's say we have a text file with the following: (in the order of: name id, name title, number people with name, name description) Code:
01 Name #1 4 This name is number one. 02 Name #2 8 This name is number two. 03 Name #3 0 This name is number three. 04 Name #4 3 This name is number four. Now keep in mind I already have a for() outputting this file fine and I'm exploding the \t's.. as the large spaces are tabs if you haven't already guessed. Within the for(), I'm able to use $value[1], $value[2], $value[3], $value[4].. to display where ever I want, granted. But now here comes the question. How can I have PHP load this file and sort the "number of people with this name" in a descending order, having everything else associated with the number of people. Example wanted output below: Name #2 has 8 people in it. It's description is "This name is number two." Name #1 has 4 people in it. It's description is "This name is number one." Name #4 has 3 people in it. It's description is "This name is number four." Name #3 has 0 people in it. It's description is "This name is number three." Any ideas? |
#2
|
||||
|
||||
I have to say this is a terrible way of storing data, you'd be best importing all this into a database
|
#3
|
||||
|
||||
Well, I can go about it displaying it that way, too.. but unfortunately the file I can't change. The file outputs from a program on the server to feed results -- nothing I can do about it.
|
#4
|
|||
|
|||
Couldn't you just run an insert query to insert the data from the text file into the database. That would give you complete control over sorting and be much more efficient.
/me thinking out load |
#5
|
|||
|
|||
i think this is some irc function that bot store all users in chan on txt file
and you want to short it out to view at forums am i right ? can you please post the entire code you made so we can see what you did worng. |
#6
|
||||
|
||||
It's true that just running queries and saving the data to the database would be more efficient, however I need to stress -- this file is written to text via a chat server (as miz noted, though not IRC) to allow webpages to update room numbers in real time. Seeing as it's real time, to me, it'd be more problematic and time/resource consuming to write the file to the database and then output those numbers each time the page was viewed for those real-time numbers. This is why I'm attempting to just display the file as is in a sorted method to keep things conventionally under control in as fast of a way possible.
Here's the setup in a hasty reveal: [1] = name. [2] = http address. [3] = current users (what I'm attempting to sort). Code:
$nameoutput = "<table width=100% cellpadding=4 cellspacing=0>"; $file = "<path>names.txt"; $lines = file($file); for ($i = 0; $i < count($lines); $i++) { $roominfo = explode("\t",$lines[$i]); $nameoutput .= "<tr><td><a href=\"" . $roominfo[2] . "\"><strong>" . $roominfo[1] . "</strong></a>, <b>" . $roominfo[3] . "</b> users.</td></tr>"; } $nameoutput .= "</table>"; (Btw guys, thanks for all your replies. I know your trying to help. ) |
#7
|
|||
|
|||
i dont think you can unless you will make a function the will contain an array
and then to reorder array (lots of work) btw use php tags instead of code tags when you posting php script |
#8
|
||||
|
||||
Yes, I'm aware of the php tags however I was quite sleepy at the time of the last posting.
At any rate - I've converted the text file from being output as it was (the loop) to now being inserted into a database every 30 minutes so I can sort things how I wish. However, this presents an entirely different problem, not necessarily major in comparison mind you, but it is slowing down the load time of the page per update. While things are now working beautifully in the "I work." sense, I'm now curious if I can drop the number of queries this is adding per update (plus there's a query checking to see even if it can update). -- There're 4 added queries in order to do this method - 1 query is added always, as it checks the time past. If the time has past for an update, 3 queries are added: delete, load data infile, and to update the time. Here's a quickie example of what's taking place: PHP Code:
Thanks guys. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|