'; echo 'View Cart

'; echo '

' . $row['ITEM_NAME'] . '

'; echo '

Back to all categories / '; echo 'Back to ' . $row['CATEGORY_NAME'] . '

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '' . $row['ITEM_NAME'] . '
' . nl2br($row['ITEM_DESCRIPTION']) . '
$' . number_format($row['PRICE'], 2) . '
'; // show link to either add or remove item from cart if (!$cart->qtyItem($row['ITEM_ID'])) { echo ''; echo 'Add to Cart'; } else { echo ''; echo 'Remove from Cart'; } echo '
'; $GLOBALS['TEMPLATE']['content'] = ob_get_clean(); } // display list of items in category else if (isset($_GET['category'])) { // verify if category parameter is valid $query = sprintf('SELECT CATEGORY_ID, CATEGORY_NAME FROM ' . '%sSHOP_CATEGORY WHERE CATEGORY_ID = %d', DB_TBL_PREFIX, $_GET['category']); $result = mysql_query($query, $GLOBALS['DB']); // category does not exist so redirect to main categories list if (!mysql_num_rows($result)) { mysql_free_result($result); header('Location: shop.php'); exit(); } $row = mysql_fetch_assoc($result); $id = $row['CATEGORY_ID']; $name = $row['CATEGORY_NAME']; mysql_free_result($result); ob_start(); echo '

'; echo 'View Cart

'; echo '

Products in ' . $name . '

'; echo '

Back to all categories

'; // retrieve items $query = sprintf('SELECT ITEM_ID, ITEM_NAME, ITEM_IMAGE ' . 'FROM %sSHOP_INVENTORY WHERE CATEGORY_ID = %d ORDER BY ITEM_NAME ASC', DB_TBL_PREFIX, $id); $result = mysql_query($query, $GLOBALS['DB']); while ($row = mysql_fetch_assoc($result)) { echo ''; echo ''; echo ''; echo '
' . $row['ITEM_NAME'] . '' . '
'; } $GLOBALS['TEMPLATE']['content'] = ob_get_clean(); } // display main list of categories and the number of products within each else { ob_start(); echo '

' . 'View Cart

'; echo '

All Categories

'; // Note: LEFT JOIN not specified so any categories without products will // not be included in the results $query = sprintf(' SELECT C.CATEGORY_ID, CATEGORY_NAME, COUNT(ITEM_ID) AS ITEM_COUNT FROM %sSHOP_CATEGORY C JOIN %sSHOP_INVENTORY I ON C.CATEGORY_ID = I.CATEGORY_ID GROUP BY C.CATEGORY_ID ORDER BY CATEGORY_NAME ASC', DB_TBL_PREFIX, DB_TBL_PREFIX); $result = mysql_query($query, $GLOBALS['DB']); echo ''; $GLOBALS['TEMPLATE']['content'] = ob_get_clean(); } // display the page include '../templates/template-page.php'; ?>