Flat File Tutorial
Moderator: General Moderators
Flat File Tutorial
Is there any site that has a comprehensive tutorial for PHP working with Flat files.
All I have come across are "built" applications for use with flat files.
Just looking for a step-by-step tutorial on how to make a basic form write to a .txt file.
And then how to display contents from that file.
Or limit what to show from that file.
Etc
does anyone have links to more detailed tutorials?
All I have come across are "built" applications for use with flat files.
Just looking for a step-by-step tutorial on how to make a basic form write to a .txt file.
And then how to display contents from that file.
Or limit what to show from that file.
Etc
does anyone have links to more detailed tutorials?
thanks ,but that is not comprehensive.phice wrote:Spoono > Tutorials > PHP > Flat Files
Comprehensive means that they show step by step and explain how to go from form, to txt, retreieve and display.
Back to this:
I have so far this:
and my text file has info like this:
How can I make it , if i only want to show those who's last column is 1 ?
Or the second column is 7?
I have so far this:
Code: Select all
<body>
Test<br>
<p>
Orders</p>
<?
$fileread = file("orders.txt");
foreach($fileread as $key => $val) {
$data[$key] = explode("|", $val); }
$totallines = count($fileread);
for($i = 0; $i < $totallines; $i++)
{
//$tel = count($fileread);
echo '<p>';
echo 'First Name: '.$data[$i][2].'<br>';
echo 'Last Name: '.$data[$i][3].'<br>';
echo 'Title: '.$data[$i][4].'<br>';
echo 'Phone: '.$data[$i][5].'<br>';
echo 'Ext.: '.$data[$i][6].'<br>';
echo 'Email: <a href=mailto:'.$data[$i][7].'>'.$data[$i][7].'</a><br>';
echo 'Img: <img src=emps/'.$data[$i][8].'><br>';
}
?>
</body>and my text file has info like this:
Code: Select all
1|7|Fnamea|Lnamea|Jobtitlea|(888) 888-888|888|888@nospamme.com|image1.jpg| | |3| |0
2|6|Fnameb|Lnameb|Jobtitleb|(888) 888-888|888|888@nospamme.com|image2.jpg| | |0| |1
3|9|Fnamec|Lnamec|Jobtitlec|(888) 888-888|888|888@nospamme.com|image3.jpg| | |0| |0
4|1|Fnamed|Lnamed|Jobtitled|(888) 888-888|888|888@nospamme.com|image4.jpg| | |0| |1How can I make it , if i only want to show those who's last column is 1 ?
Or the second column is 7?
Ok, I've done a lot of work with flat-file databases.
Basically, here's what you want. Say you have a file with a bunch of seperated values.
And that is saved in file db.txt
That's basically the best way to do it. If you're really bored, you can make a class which you can use to manipulate your flat-files. I really do believe this is the best way to go about things. Once Invision FlatBoard is released, I think you'll be able to borrow/look at the class used to work with flat-file dbs and make some pretty powerful flat-file scripts. 
And if i'm not mistaken, there are a few other flat-file boards in development now who have released classes for working with flat-file dbs. I would take a look at those.
Basically, here's what you want. Say you have a file with a bunch of seperated values.
Code: Select all
1|Anthron|anthron@hisemailaddress.com|1
2|WizyWyg|wizywyg@hisemail.com|0
3|Someoneelse|someoneelse.yahoo.com|1Code: Select all
$raw = file('db.txt');
foreach ($raw as $line)
{
$parts = explode('|', $line);
if ($partsї3] == 1)
{
// Manipulate the line of code
}
}And if i'm not mistaken, there are a few other flat-file boards in development now who have released classes for working with flat-file dbs. I would take a look at those.
playing around
I think what Anthron said is the basics for reading info from a file.
Once the information is read you have to store is some where maybe in arrays and then you would have to do array manipulation to order the info in what ever order you wanted.
Learn to love and understand http://www.php.net. They quite often have very good user comments on how to use the language.
Do a function search for files and arrays and you will get scads of info
If you are asking for some one to give up their code for you I think that you might be disappointed as we try to answer specific questions about a problem.
Take what Anthron has and play with it a little to see what you can come up with.
phpScott
Once the information is read you have to store is some where maybe in arrays and then you would have to do array manipulation to order the info in what ever order you wanted.
Learn to love and understand http://www.php.net. They quite often have very good user comments on how to use the language.
Do a function search for files and arrays and you will get scads of info
If you are asking for some one to give up their code for you I think that you might be disappointed as we try to answer specific questions about a problem.
Take what Anthron has and play with it a little to see what you can come up with.
phpScott
-
Tubbietoeter
- Forum Contributor
- Posts: 149
- Joined: Fri Mar 14, 2003 2:41 am
- Location: Germany
Re: playing around
can you explain how to create classes? How they help? What can be achieved by using them? how do they make things better? etc etc?phpScott wrote:I think what Anthron said is the basics for reading info from a file.
Once the information is read you have to store is some where maybe in arrays and then you would have to do array manipulation to order the info in what ever order you wanted.
Learn to love and understand http://www.php.net. They quite often have very good user comments on how to use the language.
Do a function search for files and arrays and you will get scads of info
If you are asking for some one to give up their code for you I think that you might be disappointed as we try to answer specific questions about a problem.
Take what Anthron has and play with it a little to see what you can come up with.
phpScott
These are not explained in the manual.
Also, the comments on the "flat file" part of the php manual do not lend much info, which is why I am asking for help on the boards.
How would go about doing the latter? Is it in the php manual (i searched, nothing on man sort or mansort )Tubbietoeter wrote:to order results you can either use the php function multisort (see php.net for info on the function plus examples) or sort the file your reading before reading it (the unix commando sort can sort by columns, see "man sort" for info).
