Reply to Re: need some help with this solution...

Your name:

Reply:


Posted by J.O. Aho on 01/30/06 19:37

Greg wrote:
> I have a new client (an ag pesticide sprayer) and he has a piece of
> software that generates reports about all the chemicals that he sprays
> on any particular day. The reports are in .txt format. As an end
> result I need to take that .txt file and and
>
> a) create an upload script for the .txt file

You could use something like the script
http://www.hotscripts.com/Detailed/31396.html

Just searching on google for "php simple upload script" generates around
2,670,000 hits, so there are many to find and use.


> b) open and read the text file into an array ( implode() ?)

explode()
otherwise you can read one line at the time and insert the things to the
database with fgets()


> c) insert the text of that array into the database.

The basics works like:
mysql_query("INSER INTO table VALUE('$text')");


> d) save the .txt file to another folder on the server to act as a back
> up should anything ever happen to the database.

Look at the upload script, and I suggest you would in this case rename the
file to have an unique name based on time/date, in case the customer happens
to upload more than once a day, not sure all are "valid" versions.


> e) create a user end that will allow clients to view which pesticides
> have been sprayed on which day, etc...

Thats quite easy, you make a SQL query and then loop the results

$result=mysql_query("SELECT * FROM table");
while($row=mysql_fetch_array($result)) {
echo $row[0]."<br>\n";
}


> f) as a side note, if someone could explain a little about cron jobs, as
> i would want the database backed up nightly and have the db file emailed
> to my inbox. I've never dabbled with cron jobs so I don't know much
> about them.

This gives you all the info you need:
man 5 contab

[minute] [hour] [day of month] [month] [day of week] [run as who] [what to do]

The five first can have a '*' which tells that it don't matter what time.
for weekday, 1 is Monday, 0 and 7 is Sunday.


> Does this sound like the best way to do this? I was just going to store
> the .txt file in the database, but figured it may be to processor
> intensive when it comes to searching ALL the files which will grow to a
> huge amount over time. I would really appreciate any feedback on the
> above logic. Thanks in advance.

If it's in a database, it's easier to search for data and if you make backups
the txt files aren't that important, but of course the database will grow with
time as the storage directory will and you can delete as easily from the
database as from the storage directory if you would need to save space.

The only real reason I can see to save the txt files, is to ensure that the
data has been inserted into the database, but this don't have to be more than
a short time storage.


//Aho

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация