diff --git a/chapter10/chapter10-project03.php b/chapter10/chapter10-project03.php index 5ed8d41748b4a208362e76982bb318bb22bab1ed..7bb2d015d18464f4e77b64e3e3b4a8b47ab2186b 100644 --- a/chapter10/chapter10-project03.php +++ b/chapter10/chapter10-project03.php @@ -85,7 +85,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'GET') { if ( isset($_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. + $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($requestedCustomer, 'orders.txt'); if ( is_null($orders) ) { @@ -103,7 +103,7 @@ </tr> <?php - CreateOrderRows($requestedCustomer[0], $orders); + CreateOrderRows($orders); ?> </table> </div> diff --git a/chapter10/orderFunctions.inc.php b/chapter10/orderFunctions.inc.php index 526d92391a9172ff0b4366a391a7933abde16e3b..e180a2735a1abeddef73c2600e58aee63f4b2a76 100644 --- a/chapter10/orderFunctions.inc.php +++ b/chapter10/orderFunctions.inc.php @@ -13,137 +13,37 @@ $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; + $orders; 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>"; + if (isset($orders)) { + return $orders; + } else { + + } } - function CreateOrderRows($customerId, $orders) { + function CreateOrderRows($orders) { #$ordersPresent = 0; - #if ($orders[$index][1] == $customerId) { + $ordersArrayLength = count($orders); + for ($index = 0; $index < ($ordersArrayLength); $index++) { 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 "<td><img src='images/book/tinysquare/" . $orders[$index][2] . ".jpg'></td>"; + echo "<td><a href='chapter10-project03.php?isbn=" . $orders[$index][2] . "'>" . $orders[$index][2] . "</td>"; + echo "<td>" . $orders[$index][3] . "</td>"; + echo "<td>" . $orders[$index][4] . "</td>"; echo "</tr>"; - - #$ordersPresent = 1; - #} - - #if ($ordersPresent == 0) { - # echo "No Orders Present."; - #} + } } ?> \ No newline at end of file