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?

    Though I cant help you much, but try searching for these commands:

    fopen()
    fwrite()
    unlink()

    I have seen a similar post a while back to someone wanting to do the same thing, but I cant find that post now. Try searching any php site for more specifics on those commands.

    This should get you started maybe: http://www.phpbuilder.com/manual/

      Originally posted by toddmarx
      Though I cant help you much, but try searching for these commands:

      fopen()
      fwrite()
      unlink()

      I have seen a similar post a while back to someone wanting to do the same thing, but I cant find that post now. Try searching any php site for more specifics on those commands.

      This should get you started maybe: http://www.phpbuilder.com/manual/

      Most of hte examples provided under each are very lacking.
      Looking for a comprehensive tutorial
      ie

      Step 1 : here's the form
      Step 2: this is how we write to a file using variables from form.
      Step 3: This is how we retrieve the information and put it into a readable format.
      Step 3a : this is how we pull only the information we want from the file.

      etc.

      Why aren't there any to find? Flat files are still useful for small tracking where a DB is not needed or not available.

        I suppose what todd was suggestion, is doing a search on this site. See the little "search"button on the top of the page? You can search the whole forum for similar questions.

        I wish I was a wizz in flat files, so I could help, but I am not.. Running database myself :-/

        Sorry.

        J.

          Originally posted by leatherback
          I suppose what todd was suggestion, is doing a search on this site. See the little "search"button on the top of the page? You can search the whole forum for similar questions.

          I wish I was a wizz in flat files, so I could help, but I am not.. Running database myself :-/

          Sorry.

          J.

          I did search. I've searched this site ,as well, nothing. Can someone point out that thread ?

          I did find one article out of the 1000's links for php, that expalins how to WRITE to a file and display "all its contents", but I know through a Mysql db you can also limit your display by a criteria
          (ie SELECT * FROM foo WHERE blahname=1 )

          Is there a way to do this with Flat files?

          Also is there away for you to delete something from a flatfile?

            one thing you may want to do is to go to www.phpclasses.org (URL??)

            Look for flat file database classes, why do all the hard work??

              Back to this:

              I have so far this:

              <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:

              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| |1
              

              How can I make it , if i only want to show those who's last column is 1 ?

              Or the second column is 7?

                actually it is quite easy, since you already know explode() function

                <br><br>

                <?php
                $fData	=	file('order.txt');
                for($line=1; $line<sizeof($fData); $line++) {
                	list($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n) = explode("|", $fData[$line]);
                
                if($n==1) {	// let say we want to show the last colomn == 1
                	$r	=	"<p>
                				FirstName : $c<br>
                				LastName : $d<br>
                				Last colomn : $n<br>
                				and so on...
                			</p><hr>";
                	echo $r;
                }
                }
                ?>
                

                just need to change the rule using the if statement, then u can choose to see what column
                u want to see.

                i see what u are trying to do (i do it last time, few years ago, but in the end swith to a db server),
                anyway, but if i gonna do it, i will do it using the WDDX function
                so that i don't have to explode everytime i want the data. I used this type of flat file temp db
                for configuration storage only. if u plan to use this flat file for records more than 30+ or > 30KB
                then u might consider to use a light database server mSQL (mini SQL).

                anyway, i advice u to use MySQL. so u can start from the right path... 🙂

                yup, there are 2 types of people... 🙂

                  Originally posted by jimson
                  actually it is quite easy, since you already know explode()

                  just need to change the rule using the if statement, then u can choose to see what column
                  u want to see.

                  i see what u are trying to do (i do it last time, few years ago, but in the end swith to a db server),
                  anyway, but if i gonna do it, i will do it using the WDDX function
                  so that i don't have to explode everytime i want the data. I used this type of flat file temp db
                  for configuration storage only. if u plan to use this flat file for records more than 30+ or > 30KB
                  then u might consider to use a light database server mSQL (mini SQL).

                  anyway, i advice u to use MySQL. so u can start from the right path... 🙂

                  yup, there are 2 types of people... 🙂

                  WDDX ? never heard of it. Can you explain?
                  As for db. no chance in hell. Server in japan, and getting them to change it so that we can use one, is like telling lemmings to stop following each other.

                  I personally rather use a DB its so much easier. so i have to figure out flat files.

                    Hi, can anyone suggest a site that offers comprehensive use of flat files?

                    And be able to return results from a flat file that only contain information that I want? Order the results? Etc?

                      Originally posted by jimson
                      u never bother to read the php manual... 🙁

                      www.php.net/wddx

                      Yup and I can't use it.

                      SO BACK to flat files..please

                        Write a Reply...