Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-30-2005, 08:41 AM
Harlequin's Avatar
Harlequin Harlequin is offline
 
Join Date: Aug 2003
Posts: 78
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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?
Reply With Quote
  #2  
Old 01-30-2005, 11:08 AM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have to say this is a terrible way of storing data, you'd be best importing all this into a database
Reply With Quote
  #3  
Old 01-30-2005, 11:40 AM
Harlequin's Avatar
Harlequin Harlequin is offline
 
Join Date: Aug 2003
Posts: 78
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 01-30-2005, 11:58 AM
Jolten Jolten is offline
 
Join Date: Mar 2004
Posts: 749
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #5  
Old 01-30-2005, 12:39 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #6  
Old 01-30-2005, 01:49 PM
Harlequin's Avatar
Harlequin Harlequin is offline
 
Join Date: Aug 2003
Posts: 78
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>";
This outputs everything in the file in a sort of way that I need with a pretty fast sweep, but how about can I punch out the sorting of the numbers in a descending order?

(Btw guys, thanks for all your replies. I know your trying to help. )
Reply With Quote
  #7  
Old 01-30-2005, 02:37 PM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #8  
Old 02-01-2005, 09:48 AM
Harlequin's Avatar
Harlequin Harlequin is offline
 
Join Date: Aug 2003
Posts: 78
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
$stamp $DB_site->query_first("SELECT * FROM time");

if (
$stamp['timestamp'] < time() - 1800) {

$query_delete $DB_site->query("DELETE FROM rooms");

$query_roomload $DB_site->query("LOAD DATA INFILE '..filepath variable..' INTO TABLE rooms (a,b,c,d,e,f,g)");

$query_stamp $DB_site->query("UPDATE time SET timestamp=" time() . "");


Is there any way possible for me to drop these queries or change this logic around to be a bit more.. clean? Or is this as clean as it gets?


Thanks guys.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:06 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04874 seconds
  • Memory Usage 2,239KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete