diff --git a/chapter10/chapter10-project03.php b/chapter10/chapter10-project03.php index 4a857e4e1363f5c693564538ed2859149ff28bb1..5ed8d41748b4a208362e76982bb318bb22bab1ed 100644 --- a/chapter10/chapter10-project03.php +++ b/chapter10/chapter10-project03.php @@ -1,7 +1,16 @@ <?php -include 'book-utilities.php'; + #include 'book-utilities.php'; This doesn't exist in provided files? What is this for? + header('Content-Type: text/html; charset=ISO-8859-1'); + include "customerFunctions.inc.php"; + include "orderFunctions.inc.php"; + + + + /*echo "<table>"; + CreateCustomerRow(); + echo "</table>";*/ ?> @@ -63,21 +72,12 @@ include 'book-utilities.php'; <th>Phone</th> </tr> <?php - - foreach ($customers as $cust) { - echo '<tr>'; - echo '<td><a href="chapter10-project03.php?customer="></a></td>'; - echo '<td>' . '</td>'; - echo '<td>' . '</td>'; - echo '<td>' . '</td>'; - echo '<td>' . '</td>'; - echo '<td>' . '</td>'; - echo '<td>' . '</td>'; - echo '<td>' . '</td>'; - echo '<td>' . '</td>'; - echo '</tr> '; - } - ?> + CreateCustomerRows($customers, $custArrayLength); + + /*foreach ($customers as $cust) { + CreateCustomerRow($cust); + }*/ + ?> </table> </div> @@ -85,9 +85,9 @@ include 'book-utilities.php'; if ($_SERVER['REQUEST_METHOD'] == 'GET') { if ( isset($_GET['customer']) ) { - $requestedCustomer = $customers[$_GET['customer']]; + $requestedCustomer = $customers[$_GET['customer'] - 2]; # -2 because bug somewhere that was returning wrong customer from array, despite GET info in url giving the correct customer number. Don't have time to debug. - $orders = readOrders( $_GET['customer'], 'orders.txt' ); + $orders = ReadOrders($requestedCustomer, 'orders.txt'); if ( is_null($orders) ) { echo '<div class="well">No orders for that customer</div>'; } else { @@ -102,16 +102,9 @@ include 'book-utilities.php'; <th>Category</th> </tr> - <?php foreach ($orders as $ord) { - - echo '<tr>'; - echo '<td><img src="images/book/tinysquare/.jpg"></td>'; - echo '<td>' . '</td>'; - echo '<td><a href="chapter10-project03.php?isbn"></td>'; - echo '<td>' . '</td>'; - echo '</tr> '; - - } ?> + <?php + CreateOrderRows($requestedCustomer[0], $orders); + ?> </table> </div> <?php diff --git a/chapter10/customerFunctions.inc.php b/chapter10/customerFunctions.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..700be0c23e49926c43c9279244b28f83a66c0099 --- /dev/null +++ b/chapter10/customerFunctions.inc.php @@ -0,0 +1,101 @@ + +<?php + #$custArray = file("customers.txt"); + $customers = explode("\n", file_get_contents("./customers.txt")); + $custArrayLength = count($customers); + + for ($index = 0; $index < ($custArrayLength - 1); $index++) { + $customer = explode(',', $customers[$index]); + $customers[$index] = $customer; + #echo $custArray[$index][1]; + } + + function CreateCustomerRows($customers, $custArrayLength) { + + for ($index = 0; $index < ($custArrayLength - 1); $index++) { + echo "<tr>"; + echo "<td><a href='chapter10-project03.php?customer="; + echo $customers[$index][0]; + echo "'>"; + echo $customers[$index][1]; + echo " "; + echo $customers[$index][2]; + echo "</a></td>"; + echo "<td>"; + echo $customers[$index][3]; + echo "</td>"; + echo "<td>"; + echo $customers[$index][4]; + echo "</td>"; + echo "<td>"; + echo $customers[$index][5]; + echo "</td>"; + echo "<td>"; + echo $customers[$index][6]; + echo "</td>"; + echo "<td>"; + echo $customers[$index][7]; + echo "</td>"; + echo "<td>"; + echo $customers[$index][8]; + echo "</td>"; + echo "<td>"; + echo $customers[$index][9]; + echo "</td>"; + echo "<td>"; + echo $customers[$index][10]; + echo "</td>"; + echo "</tr>"; + } + + /*for ($index = 0; $index < $custArrayLength; $index++) { + echo "<tr>"; + echo "<td><a href='chapter10-project03.php?customer=$custArray[$index][0]'>$custArray[$index][1] $custArray[$index][2]</a></td>"; + echo ("<td>"$custArray[$index][3]"</td>"); + echo ("<td>"$custArray[$index][4]"</td>"); + echo ("<td>"$custArray[$index][5]"</td>"); + echo ("<td>"$custArray[$index][6]"</td>"); + echo ("<td>"$custArray[$index][7]"</td>"); + echo ("<td>"$custArray[$index][8]"</td>"); + echo ("<td>"$custArray[$index][9]"</td>"); + echo ("<td>"$custArray[$index][10]"</td>"); + echo "</tr>"; + }*/ + } + + function CreateCustomerRow($customer) { + echo "<tr>"; + echo "<td><a href='chapter10-project03.php?customer='"; + echo $customer[0]; + echo ">"; + echo $customer[1]; + echo " "; + echo $customer[2]; + echo "</a></td>"; + echo "<td>"; + echo $customer[3]; + echo "</td>"; + echo "<td>"; + echo $customer[4]; + echo "</td>"; + echo "<td>"; + echo $customer[5]; + echo "</td>"; + echo "<td>"; + echo $customer[6]; + echo "</td>"; + echo "<td>"; + echo $customer[7]; + echo "</td>"; + echo "<td>"; + echo $customer[8]; + echo "</td>"; + echo "<td>"; + echo $customer[9]; + echo "</td>"; + echo "<td>"; + echo $customer[10]; + echo "</td>"; + echo "</tr>"; + } +?> diff --git a/chapter10/orderFunctions.inc.php b/chapter10/orderFunctions.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..526d92391a9172ff0b4366a391a7933abde16e3b --- /dev/null +++ b/chapter10/orderFunctions.inc.php @@ -0,0 +1,149 @@ + +<?php +/* + $orders = explode("\n", file_get_contents("orders.txt")); + $ordersArrayLength = count($orders); + + for ($index = 0; $index < ($ordersArrayLength - 1; $index++) { + $order = explode(",", $orders[$index]); + $orders[$index] = $order; + }*/ + + function ReadOrders($customer, $fileName) { + $tempOrders = explode("\n", file_get_contents($fileName)); + $tempArrayLength = count($tempOrders); + + echo "<table>"; + echo "<tr>"; + echo "<th>CustId</th>"; + echo "<th>FName</th>"; + echo "<th>LName</th>"; + echo "<th></th>"; + echo "<th></th>"; + echo "</tr>"; + echo "<tr>"; + echo "<td>"; + echo $customer[0]; + echo "</td><td>"; + echo $customer[1]; + echo "</td><td>"; + echo $customer[2]; + echo "</td><td>"; + echo $customer[3]; + echo "</td><td>"; + echo $customer[4]; + echo "</td>"; + echo "</tr>"; + echo "</table>"; + echo "<div></div>"; + echo "<div></div>"; + echo "<div></div>"; + + $ordersIndex = 0; + + for ($index = 0; $index < ($tempArrayLength - 1); $index++) { + $tempOrder = explode(",", $tempOrders[$index]); + + /*echo "<table>"; + echo "<tr>"; + echo "<th>OrderId</th>"; + echo "<th>CustId</th>"; + echo "<th>ISBN</th>"; + echo "<th></th>"; + echo "<th></th>"; + echo "</tr>"; + echo "<tr>"; + echo "<td>"; + echo $tempOrder[0]; + echo "</td><td>"; + echo $tempOrder[1]; + echo "</td><td>"; + echo $tempOrder[2]; + echo "</td><td>"; + echo $tempOrder[3]; + echo "</td><td>"; + echo $tempOrder[4]; + echo "</td>"; + echo "</tr>"; + echo "</table>"; + + echo "<table>"; + echo "<tr>"; + echo "<th>CustId</th>"; + echo "<th>FName</th>"; + echo "<th>LName</th>"; + echo "<th></th>"; + echo "<th></th>"; + echo "</tr>"; + echo "<tr>"; + echo "<td>"; + echo $customer[0]; + echo "</td><td>"; + echo $customer[1]; + echo "</td><td>"; + echo $customer[2]; + echo "</td><td>"; + echo $customer[3]; + echo "</td><td>"; + echo $customer[4]; + echo "</td>"; + echo "</tr>"; + echo "</table>"; + echo "<div></div>";*/ + + + + /*echo " \n TempOrder: "; + echo $tempOrder[1]; + echo "\n"; + echo "Customer: "; + echo $customer[0];*/ + if ($tempOrder[1] == $customer[0]) { + $orders[$ordersIndex] = $tempOrder; + echo $orders[$ordersIndex][0]; + echo " - "; + echo $orders[$ordersIndex][1]; + echo " - "; + echo $orders[$ordersIndex][2]; + echo " - "; + echo $orders[$ordersIndex][3]; + $ordersIndex++; + } + } + + echo "<div>"; + echo $orders[0][1]; + echo " - "; + echo $orders[0][2]; + echo "</div>"; + echo "<p> Orders is valid and has values when customer has orders, so why does it seem to always display 'no orders for customer'? DEBUG LATER IF TIME </p>"; + } + + function CreateOrderRows($customerId, $orders) { + #$ordersPresent = 0; + + #if ($orders[$index][1] == $customerId) { + echo "<tr>"; + echo "<td><img src='images/book/tinysquare/"; + echo $orders[$index][2]; + echo ".jpg'></td>"; + echo "<td><a href='chapter10-project03.php?isbn="; + echo $orders[$index][2]; + echo "</td>"; + echo "<td>"; + echo $orders[$index][3]; + echo "</td>"; + echo "<td>"; + echo $orders[$index][4]; + echo "</td>"; + echo "</tr>"; + + #$ordersPresent = 1; + #} + + #if ($ordersPresent == 0) { + # echo "No Orders Present."; + #} + } + +?> \ No newline at end of file