<html>
<head>
<title>Retrieve data from file</title>
</head>
<body bgcolor=lightyellow>
<h1><center>The Ice Cream Shop</center></h1>
<h2>Retrieve data from file</h2>
<table bgcolor=#dddddd border=5 outset width=700>
<tr bgcolor=tan>
<th>Name</th><th>Address</th><th>Flavors</th><th>Toppings</th><th>Credit Card</th>
</tr>
<?php
$filename = '/home/sultans/web/data/cust_order.file'; #server file
// $filename = '../data/cust_order.file'; #local PC file
$data = Array(); #define an array
read_data2();
display();
//===============================================================================
function display()
{
global $data;
foreach($data as $rec)
{
$fields = explode('||',$rec);
$first = $fields[0];
$last = $fields[1];
$address = $fields[2];
$flavor = $fields[3];
$topping = $fields[4];
$creditCard = $fields[5];
$address2 = str_replace("__", "<br>", $address); #replace __ with <br>
$flavor2 = str_replace("," , "<br>", $flavor);
$topping2 = str_replace("," , "<br>", $topping);
print "<tr valign=top>";
print "<td>$first $last </td> <td>$address2</td>
<td>$flavor2</td> <td>$topping2</td> <td>$creditCard</td>";
print "</font></tr>";
}
}
//===============================================================================
function read_data()
{
global $filename, $data;
$handle = fopen ($filename, 'r')
or die ("Cannot open $input for read");
$data = file($filename) #read entire file into array
or die ("Cannot read from file");
fclose($handle);
}
//===============================================================================
function read_data2()
{
global $filename, $data;
$handle = fopen ($filename, 'r')
or die ("Cannot open $input for read");
$i=0;
// $data[$i++] = fgets($handle)
// or die ("Cannot read from file");
while($line = fgets($handle))
$data[$i++] = $line;
fclose($handle);
}
//===============================================================================
?>
</table>
<?php include "../include.php"; ?> <!-- hyperlink to see the code -->
</body>
</html>