Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flat File Tutorial

Status
Not open for further replies.

WizyWyg

Technical User
Jan 31, 2001
854
JP
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?
 
Hi,


Hope this helps!

relax.gif


Keep up to date with my 2003 NHL Playoffs Wallpaper
 
Comprehensive...like for beginner php programmers. ^_^

ie:
Step 1 : this is a form
Step 2 : how to write to a txt file
Step 3 : this is how we retrieve information from a file
Step 3a : this is how we retrieve certain information from a file
Step 4 : this is how we format our information
 
Back to this:

I have so far this:

Code:
<body>
Test<br>
<p>
Orders</p>
<?
$fileread = file(&quot;orders.txt&quot;);
foreach($fileread as $key => $val) { 
	$data[$key] = explode(&quot;|&quot;, $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:
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?
 
Hi,

I don't think this is what you should be using a flat file for, this could be way more work than it's worth. Can you use mysql db's? That is your best bet, then you can query the db and call whatever you want based on pretty much anything you want.

A simple SQL query for what you want would read as follows:

SELECT * FROM `table_name` WHERE `(last column)` = 1

You might also consider using an ms access db if you can't use mysql.

Hope this helps!

relax.gif


Keep up to date with my 2003 NHL Playoffs Wallpaper
 
wrap your echo's in a

Code:
$check_val = 1;
if ($data[$i][14] == $check_val) {
   ...
}

If you're going to do alot of flatfile work, I'd also suggest looking into the trim() function... you'll probably get alot of use out of it (for example, in this case there's a possibility you'll show no rows because $data[$i][14] will really equal 1\n).

-Rob
 
spyder - no, no db . server in japan, and japan doesn't want to install any dbs for fear of security. Dont ask, im not going to argue with japanese businessmen.
 
skiflyer,

what is that you just posted?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top