-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvieworders2.php
More file actions
55 lines (51 loc) · 1.38 KB
/
vieworders2.php
File metadata and controls
55 lines (51 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
//create short variable name
$DOCUMENT_ROOT = $_SERVER[ 'DOCUMENT_ROOT' ];
$FILE = "$DOCUMENT_ROOT/order.txt";
?>
<html>
<head>
<title>Bob's Auto parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto parts</h1>
<h2>Customer Orders</h2>
<?php
//Read in the entire file.
//Each order becomes an element in the array
$orders = file($FILE);
//count the number of orders in the array
$number_of_orders = count($orders);
if ($number_of_orders == 0){
echo '<p><strong>No order pending.
Please try again later.</strong></p>';
}
echo "<table border=\"1\">\n";
echo "<tr><th bgcolor=\"#CCCCFF\">Order Date</th>
<th bgcolor=\"#CCCCFF\">Tires</th>
<th bgcolor=\"#CCCCFF\">Oil</th>
<th bgcolor=\"#CCCCFF\">Spark Plugs</th>
<th bgcolor=\"#CCCCFF\">Total</th>
<th bgcolor=\"#CCCCFF\">Address</th>
</tr>";
for ($i = 0; $i < $number_of_orders; $i++){
//split up each line
$line = explode("\t", $orders[$i]);
//keep only the number od items ordered
$line[1] = intval($line[1]);
$line[2] = intval($line[2]);
$line[3] = intval($line[3]);
//output each order
echo "<tr>
<td>".$line[0]."</td>
<td align=\"right\">".$line[1]."</td>
<td align=\"right\">".$line[2]."</td>
<td align=\"right\">".$line[3]."</td>
<td align=\"right\">".$line[4]."</td>
<td>".$line[5]."</td>
</tr>";
}
echo '</table>';
?>
</body>
</html>