Location: PHPKode > projects > Uiga Cart > library/product-functions.php
<?php
require_once 'config.php';

/*********************************************************
*                 PRODUCT FUNCTIONS 
*********************************************************


/*
	Get all the products in certain category 
*/
function getProductList($catId)
{
	$children = array_merge(array($catId), getChildCategories(NULL, $catId));
	$children = ' (' . implode(', ', $children) . ')';

	$sql = "SELECT pd_id, pd_name, pd_price, pd_thumbnail, pd_qty, c.cat_id, pd_phase_out
	        FROM tbl_product pd, tbl_category c
			WHERE pd.cat_id = c.cat_id AND pd.cat_id IN $children 
	        ORDER BY pd_name";
	$result =& dbQuery($sql);
	
	$products  = array();
	while ($row =&dbFetchAssoc($result)) {
		extract($row);
		if ($pd_thumbnail) {
			$pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail;
		} else {
			$pd_thumbnail = WEB_ROOT . 'images/no-image-small.png';
		}

		$products[] = array('url'   => $_SERVER['PHP_SELF'] . "?c=$catId&p=$pd_id",
		                    'image' => $pd_thumbnail,
							'name'  => $pd_name,
							'price' => $pd_price,
							'qty'   => $pd_qty,
							'phase_out' => $pd_phase_out);
							
	} // end while
	
	return $products;	
}

function getProductDetail($pdId, $catId)
{
	
	$_SESSION['shoppingReturnUrl'] = $_SERVER['REQUEST_URI'];
	
	// get the product information from database
	$str = "SELECT pd_name, pd_description, pd_price, pd_image, pd_qty, pd_phase_out
			FROM tbl_product
			WHERE pd_id = $pdId";
	
	$result =&dbQuery($str);
	$row    =&dbFetchAssoc($result);
	extract($row);
	
	$row['pd_description'] = nl2br($row['pd_description']);
	
	if ($row['pd_image']) {
		$row['pd_image'] = WEB_ROOT . 'images/product/' . $row['pd_image'];
	} else {
		$row['pd_image'] = WEB_ROOT . 'images/no-image-large.png';
	}
	
	$row['cart_url'] = "cart.php?action=add&p=$pdId";
	
	return $row;			
}

function fetchProduct($pdName)
{
	$products  = array();
	$sql = "SELECT pd_id, pd_name, pd_price, pd_thumbnail, pd_qty, c.cat_id, pd_phase_out
	        FROM tbl_product pd, tbl_category c
			WHERE pd.cat_id = c.cat_id AND pd.pd_name like '%$pdName%'
	        ORDER BY pd_name";
	$result =& dbQuery($sql);
	
	$products  = array();
	while ($row =&dbFetchAssoc($result)) {
		extract($row);
		if ($pd_thumbnail) {
			$pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail;
		} else {
			$pd_thumbnail = WEB_ROOT . 'images/no-image-small.png';
		}

		$products[] = array('url'   => $_SERVER['PHP_SELF'] . "?c=$cat_id&p=$pd_id",
							'image' => $pd_thumbnail,
							'name'  => $pd_name,
							'price' => $pd_price,
							'qty'   => $pd_qty,
							'phase_out' => $pd_phase_out);
							
	} // end while
	
	return $products;
	
}

?>
Return current item: Uiga Cart