Okay, so I'm pretty new to PHP...Call me a newbie, but everything works great if it's completely static, but the problem I have is if I need different results depending on user action. The problem lies with needing to use PHP to take information from files, but otherwise it would work much better alone in Javascript (well, at least from my understanding) since javascript functions can be used after the page loads.

Here's what I want to do:

I have a pile of files, I want PHP to load the data from each file. (they're mostly text documents), but I want to be able to organize the order of the files (and the data in them) on the fly (only for viewing purposes, the name of the files would stay the same).

The only way I could think of how to do this, is to create a cache of all the data I formatted in PHP for each way I want the data to be viewed, but that's obviously extremely inefficient (like I'd be loading the data 5 different ways when they open the page instead of only once and then once again when they reformat to the desired organization).

If they were short documents, that'd be fine - process it each way, create 5 caches, 1 for each format it should be viewed, let PHP process into each way and just pick the cache as I go...or something like that. I don't even know if that would work... :confused:

But what I think I want to do is somehow reload the page to force PHP to format it in a different way each time. I can't think of any other way... :(

I hope some of that makes sense. I'm not looking for someone to just throw me all the code for it, just what possibilities are available to do this? I'm just looking for an idea, and any and all are welcome! Thanks in advance.

but I want to be able to organize the order of the files (and the data in them) on the fly (only for viewing purposes, the name of the files would stay the same).

Elaborate on this. How do you want to organize them, and why?

Thanks. Took me about 6 hours, but I just figured out a way to get it to work actually...well mostly. I created a script for each way I wanted to format it. Then the page itself will check a variable and use whichever include for each way I want it formatted, and I will use javascript onchange from a dropdown to pass the variable to the same page using a hidden input value and do this.form.submit(); with form action to the same page itself, to get it to submit that value to the page itself to reload the page again and cause it to "re-include" the different php script for the different way I want it formatted when it reloads the page. Lengthy, longwinded, and kind of ridiculous...but it works, and it does almost exactly what I want lol...All but one thing...but now I have a new problem.

I've figured out everything except for how to sort a particular number from the lines the page is formatting (from the files it loads) Like the way I did it was bring in line by line each file until the endkey, but I want to organize the paragraphs (since one of the methods of formatting is to bring up a numeric summary in the page)...So each document it loads has a number in the middle of the line I need to pick up, but I'm not sure how to get at it...I want to sort each line/paragraph by the number in the middle. I'm basically using PHP to format a lot of data into a usable form that I can make a kind of spreadsheet out of...but the numbers and the information with them have to stay together, but be ordered by the numbers themselves....if that made any sense. :(

Like if I "explode" each line/paragraph, it separates the numbers from what's before and after it, so I can't do that...and without breaking it up, using "sort()" to sort numerically won't work. To make matters worse, the numbers have a random numbers of digits - from 1 to 5. So I can't substr() it either. If it helps, the numbers are usually near the middle end, like 2nd last thing and have "s p a c e s" between them and the rest of the content.

wouldn't it be better if you just used a database to store this data instead of files and then php cud be easily used to work on this data ?


I never liked working with files. just my 0.02 cents

wouldn't it be better if you just used a database to store this data instead of files and then php cud be easily used to work on this data ?


I never liked working with files. just my 0.02 cents

That's part of the point...I didn't make all the files, but I have to be able to import the data somehow. It wasn't organized the same, so I have to make it work, lol. :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.