Portal Home > Knowledgebase > Articles Database > PHP - collecting information from a text file ?


PHP - collecting information from a text file ?




Posted by XtremeAU, 09-08-2008, 02:43 AM
Hi all, I have a question in regards to coding to a certain platform. Basically what i have done so far is design a little form, when data is entered and 'submitted' - the entered data writes to a text file. What i have then done is, had the data from the text file display into a html table What i would like to do now is use what is in the text file and display the relevant data to the chosen category. The data to be entered is as follows: ID, First Name, Last Name, *Department*, Salary, Date of Employment. Essentially i would like to be able to select from a choice of departments and then see how many employees are in the one department. What i have done so far..... This is the code that displays the contents of the text file into a table: I'm trying to get the 'department' category to display using variations of this code: I'd appreciate some pointers as to where i am going wrong.

Posted by mod_webhosting, 09-08-2008, 04:54 AM
Is a use of the database an option for you? If it is then you would be querying the database to find information you need. Something like SELECT COUNT(*) FROM records WHERE department = 7; would return the number of employees in a particular department. Sure, this problem can be resolved using text files only, but it would complicate things.

Posted by bigfan, 09-08-2008, 10:00 AM
Using a database is a better solution, but using a text file should be fairly simple. In either case, in your coding you should separate the data processing from its display, and you should use arrays more to your advantage. Something like this: Last edited by bigfan; 09-08-2008 at 10:13 AM.

Posted by awatson, 09-08-2008, 03:56 PM
Assuming you control the code that outputs the html flat file, you could also "seed" in some comments that won't show up for the user, but will make finding fields easier, i.e. Then your processing script just has to look for what's between the comments, which should be pretty straightforward with preg_match. But a real database is still a better option.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
dot5hosting down (Views: 793)
Hide Server Location (Views: 731)

Language: