Page 1 of 1
File handling documentation
Posted: Sun Jul 01, 2007 3:52 am
by Dilbert137
Dear All,
I need to create a function for updating pricelist on database and need some documentations on file handling on PHP. Could you please refer me a documentation?
Thanks and Best Regards
Dilbert137
Posted: Sun Jul 01, 2007 3:56 am
by Benjamin
A: What have you tried?
B:
php.net
Posted: Sun Jul 01, 2007 4:07 am
by alex.barylski
fopen, fread, fwrite are the only functions you need to know.
You could use my CSV class to simplify matters, located here:
viewtopic.php?t=47855
Whats really weird, is you use the term database and file handling in the same sentance, which is accurate when using DB tin it's most generic sense. However in PHP when you say DB, you typically mean MySQL, SQLite, etc.
So just to clear things up, what exactly are you looking to use? DB or File system?
Posted: Sun Jul 01, 2007 4:34 am
by Dilbert137
I will use Mysql as database and a table price in which prices must be updated from a text file. In the text file there will be product id and prices. I will import data from the text file and write it in my mysql table.
Thanks
Dilbert137
Posted: Sun Jul 01, 2007 6:02 am
by superdezign
In that case, make a small script that just takes the data in a textarea and paste it in there. Press submit and have it add each record to the database using the submitted data.
Posted: Sun Jul 01, 2007 6:28 am
by Dilbert137
Hi superdezign,
No the solution to take from a textarea is not recommended when you have more than 1000 product items prices to be changed and when you have different price list. Data must be taken from a text file or automatic update. But my solution for the moment is this one.
Regards
Dilbert137
Posted: Sun Jul 01, 2007 8:02 am
by superdezign
When dealing with text files, textareas are actually perfectly fine. You'll be dealing with the exact same amount of data.
If you really don't want to use it, you should have already visited the resources we've given so far and looked into the file handling functions. The processing will be the same.
Posted: Sun Jul 01, 2007 8:25 am
by Dilbert137
Sorry I don't really understand you. Maybe your solution is fine. My understanding of textarea is the testarea used in forms. Documentation is needful as it will be confusing. In IT there are so many way that it can be done but with textarea not for so huge data and when specific field have to be extracted.
I use textarea when there is wordings to be inserted in table field but not for specific data to be collect from.
<textarea></textarea>
Regards
Dilbert137
Posted: Sun Jul 01, 2007 8:34 am
by superdezign
Well the best way to understand a text area is that it's just text. There's no limit. It would only remove the need to handle the files.
Posted: Sun Jul 01, 2007 10:11 am
by volka
If you have file that contains somezhing like
productid,price
productid,price
productid,price
you might be interested in
http://de2.php.net/fgetcsv
Code: Select all
<?php
$fp = fopen('data.txt', 'rb') or die('cannot open file');
while( !feof($fp) ) {
$row = fgetcsv($fp);
print_r($row);
}
Posted: Sun Jul 01, 2007 11:48 am
by Dilbert137
Thanks
Dilbert137
Posted: Sat Jul 14, 2007 12:47 pm
by Dilbert137
I thank you all. I have been able to import data from a file so that to insert it into my table. The help of all those replying to my post was helpful to me.
Thanks a lot
Dilbert137