';
echo '
';
echo '' . $row['ITEM_NAME'] . '
';
echo 'Back to all categories / ';
echo 'Back to ' .
$row['CATEGORY_NAME'] . '
';
echo '';
echo '';
echo ' | ';
echo '' . $row['ITEM_NAME'] . ' |
';
echo '' . nl2br($row['ITEM_DESCRIPTION']) . ' |
';
echo '$' . number_format($row['PRICE'], 2) . ' ';
// show link to either add or remove item from cart
if (!$cart->qtyItem($row['ITEM_ID']))
{
echo '';
echo ' ';
}
else
{
echo '';
echo ' ';
}
echo ' |
';
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 '
';
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 '';
}
$GLOBALS['TEMPLATE']['content'] = ob_get_clean();
}
// display main list of categories and the number of products within each
else
{
ob_start();
echo '' .
'
';
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 '';
while ($row = mysql_fetch_assoc($result))
{
printf('- %s (%d %s)
',
$row['CATEGORY_ID'],
$row['CATEGORY_NAME'],
$row['ITEM_COUNT'],
(($row['ITEM_COUNT'] == 1) ? 'product' : 'products'));
}
mysql_free_result($result);
echo '
';
$GLOBALS['TEMPLATE']['content'] = ob_get_clean();
}
// display the page
include '../templates/template-page.php';
?>