MySQL to Flat-File

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Dr. PHP
Forum Newbie
Posts: 11
Joined: Sun Nov 24, 2002 8:46 am

MySQL to Flat-File

Post by Dr. PHP »

Hello!

I've never done a lot of databases before, so I'm a bit new to them in general, but I have a good programming sense and knowledge. I am working on a contract script right now for a company who keeps track of all news headlines with their company name in them so the Media/PR department can quickly respond to the press regarding certain issues. I've got most things worked out, but a fairly simple question.

One major option in the script is to search the database for articles on certain dates, by categories, keywords, etc. If the database is going to be fairly large database of stories. When searching for stories...what is the easiest way to list the stories? For example....is there an easy way to develop the output HTML (just the story name for example), then continue searching the database? Or can I just go through the entire database while printing out the headlines in a flat txt file, then use PHP to render the text file and display the headlines 10 per page. Is that redundant?

I figure there is a way to just list the headline then continue searching the databse, or possibly have a flag field and if the story gets flagged, it gets outputted at the end.

Make any sense...any brief ideas? Thanks!
Bitmaster
Forum Newbie
Posts: 20
Joined: Thu Nov 21, 2002 8:42 am

Searching DB

Post by Bitmaster »

Flagging a record as you suggested would definately not work in a concurrent environment (ie multiple users searching at the same time using different criteria will overwrite each others flags).
Saving to a flat text file is also not a very good idea because you have to generate unique file names for each request and keep track of all those names, for the same reason as above: concurrency. And you also have to ask yourself who will delete the file and when ?
My suggestion would be to render into HTML an article's title and summary as soon as you decide its a match for the search criteria, and provide a link to another script page that will extract and display the entire contents of an article, like web search engines do.
Also, the simplest approach to display 'paged' results (only 10 or so records per page) is to run the entire query every time a set of results is required, and display only a few of those records. This is slow, but simple enough to get you started. For more advanced performance, you could implement a result cache (kinda like that temporary flat file). But maintaining this cache is not an easy task, some timeout mechanisms are required to 'expire' the cache and delete the file.
Post Reply