Location: PHPKode > projects > Simple PHP Shopping cart - asaancart > asaancart v-0.9/shop/classes/functions.php
<?php
function getStoreBasicInfo($params="*"){
	$sql = "SELECT $params FROM store_settings WHERE store_id=1";
	$results = mysql_query($sql);
	
	while($row = mysql_fetch_assoc($results) )
	{
		$storeBasicInfo[] = $row;
	}
	return $storeBasicInfo;
}

function getStoreBasicInfoByOneParam($params="*"){
	$sql = "SELECT $params FROM store_settings WHERE store_id=1";
	$results = mysql_query($sql);
	
	while($row = mysql_fetch_array($results) )
	{
		$storeBasicInfo = $row[0];
	}
	return $storeBasicInfo;
}

function getParentCategories(){
	$sql = "SELECT DISTINCT parent_cat_id FROM sub_category";
	$results = mysql_query($sql);
	
	while($row = mysql_fetch_assoc($results) )
	{
		$sql_p = "SELECT DISTINCT * FROM category WHERE category_id=".$row['parent_cat_id'];
		$results_p = mysql_query($sql_p);
		while($row_p = mysql_fetch_assoc($results_p) )
		{	$cat_parent_list[] = $row_p;	}	
	}
	return $cat_parent_list;
}

function getSubCategories($category_id){
	$sql = "SELECT * FROM category WHERE category_id IN (SELECT category_id FROM `sub_category` WHERE parent_cat_id=$category_id) ORDER BY category_name";
	$results = mysql_query($sql);
	
	while($row = mysql_fetch_array($results) )
	{
		$subCategories[] = $row;
	}
	return $subCategories;
}

function getTotalSubCategories($category_id){
	$sql = "SELECT count(category_id) FROM category WHERE category_id IN (SELECT category_id FROM `sub_category` WHERE parent_cat_id=$category_id)";
	$results = mysql_query($sql);
	
	while($row = mysql_fetch_array($results) )
	{
		$totalSubCategories = $row[0];	
	}
	return $totalSubCategories;
}

function getCategories($params="*"){

	$sql = "SELECT $params FROM category WHERE category_id IN (SELECT DISTINCT parent_cat_id FROM sub_category) ORDER BY category_name";
	$results = mysql_query($sql);
	$total_cat = mysql_num_rows($results);	
	while($row = mysql_fetch_assoc($results) )
	{
		$cat_list[] = $row;		
	}
	
	return $cat_list;
}

function getCategoryById($category_id){

	$sql = "SELECT * FROM category WHERE category_id=$category_id";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$categoryInfo[] = $row;		
	}
	
	return $categoryInfo;
}

function getTotalCategories(){

	$sql = "SELECT count(category_id) FROM category";
	$results = mysql_query($sql);
	$total_cat = mysql_num_rows($results);	
	while($row = mysql_fetch_assoc($results) )
	{
		$totalCategories = $row[0];		
	}
	
	return $totalCategories;
}

function getBrands(){

	$sql = "SELECT * FROM brands ORDER BY brand_name";
	$results = mysql_query($sql);
	$total_brand = mysql_num_rows($results);
	
	while($row = mysql_fetch_assoc($results) )
	{
		$all_brands[] = $row;		
	}
		
	return $all_brands;
}

function getTotalBrands(){

	$sql = "SELECT count(brand_id) FROM brands";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalBrands = $row[0];		
	}
		
	return $totalBrands;
}


function getBrandById($brand_id){

	$sql = "SELECT * FROM brands WHERE brand_id=$brand_id";
	$results = mysql_query($sql);
	
	while($row = mysql_fetch_assoc($results) )
	{
		$brandInfo[] = $row;		
	}
		
	return $brandInfo;
}

function getBlockContentsByHeading($block_heading){
	$sql = "SELECT * FROM content_page WHERE page_id IN 
			(
			SELECT page_id from block_contents WHERE block_id=
				(SELECT block_id FROM content_block WHERE block_heading='$block_heading')
			)";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$block_contents[] = $row;
	}
	return $block_contents;
}


function getBlockContentsById($block_id){
	$sql = "SELECT * FROM content_page WHERE page_id IN 
			(
			SELECT page_id from block_contents WHERE block_id=
				(SELECT block_id FROM content_block WHERE block_id=$block_id)
			)";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$block_contents[] = $row;
	}
	return $block_contents;
}

function getTotalBlocks(){

	$sql = "SELECT count(block_id) FROM content_block";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalBlocks = $row[0];		
	}
		
	return $totalBlocks;
}

function getPageDataById($page_id){
	$sql = "SELECT * FROM content_page WHERE page_id=$page_id";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$pageData[] = $row;
	}
	return $pageData;
}

function getProductImagesById($id){
		//get pro image
		$sql_img = "SELECT * FROM product_images WHERE product_id='$id' ORDER BY is_main DESC";
		$results_img = mysql_query($sql_img);
		while($row_img = mysql_fetch_assoc($results_img) )
		{
			$product_images[] = $row_img;
		}
		return $product_images;
}

function getProductImages(){
		//get pro image
		$sql_img = "SELECT * FROM product_images ORDER BY product_id";
		$results_img = mysql_query($sql_img);
		while($row_img = mysql_fetch_assoc($results_img) )
		{
			$product_images[] = $row_img;
		}
		return $product_images;
}


function getImagesByProductId($product_id, $dir="ASC"){
		//get pro image
		$sql_img = "SELECT * FROM product_images WHERE product_id='$product_id' ORDER BY is_main $dir";
		$results_img = mysql_query($sql_img);
		while($row_img = mysql_fetch_array($results_img) )
		{
			$product_images[] = $row_img;
		}
		return $product_images;
}

function getProductMainImage(){
		//get pro image
		$sql_img = "SELECT * FROM product_images WHERE is_main=1";
		$results_img = mysql_query($sql_img);
		while($row_img = mysql_fetch_assoc($results_img) )
		{
			$product_images[] = $row_img;
		}
		return $product_images;
}

function getProductMainImageById($product_id){
		//get pro image
		$sql_img = "SELECT image_filename FROM product_images WHERE is_main=1 AND product_id='$product_id'";
		$results_img = mysql_query($sql_img);
		while($row_img = mysql_fetch_array($results_img) )
		{
			$productMainImage = $row_img[0];
		}
		return $productMainImage;
}

function getProductAttributesById($product_id){

		$sql_pro_attrib = "SELECT * FROM product_attributes WHERE product_id='$product_id'";
		$results_pro_attrib = mysql_query($sql_pro_attrib);
		while($row_pro_attrib = mysql_fetch_array($results_pro_attrib) )
		{
			$product_attributes[] = $row_pro_attrib;
		}
		
		return $product_attributes;
					
}

function getProductAttributes(){

		$sql_pro_attrib = "SELECT * FROM product_attributes";
		$results_pro_attrib = mysql_query($sql_pro_attrib);
		while($row_pro_attrib = mysql_fetch_assoc($results_pro_attrib) )
		{
			$product_attributes[] = $row_pro_attrib;
		}
		
		return $product_attributes;
					
}



function getProducts($params="*"){
	$sql = "SELECT $params FROM products WHERE product_status='online' ORDER BY product_name";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$allProducts[] = $row;
	
	}
	return $allProducts;
}

function getProductColumnById($params="product_id", $product_id){
	$sql = "SELECT $params FROM products WHERE product_status='online' AND product_id='$product_id'";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$productsColumnInfo = $row[0];
	
	}
	return $productsColumnInfo;
}

function getProductById($product_id){
	$sql = "SELECT * FROM products WHERE product_status='online' AND product_id='$product_id'";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$productData[] = $row;
	
	}
	return $productData;
}

function getTotalProducts(){
	$sql = "SELECT count(product_id) FROM products WHERE product_status='online' ORDER BY product_name";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalProducts = $row[0];
	
	}
	return $totalProducts;
}
//product variant qty
function getProductTotalQtyByVariants($product_id){
	$sql = "SELECT SUM(qty) FROM product_variants WHERE show_variant='yes' AND product_id='$product_id'";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalProductQty = $row[0];
	
	}
	return $totalProductQty;
}
function getProductTotalQtyOfVariant($id){
	$sql = "SELECT qty FROM product_variants WHERE show_variant='yes' AND id=$id";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalQtyOfVariant = $row[0];
	
	}
	return $totalQtyOfVariant;
}

function getProductVariantNameById($id){
	$sql = "SELECT variant_name FROM variants WHERE variant_id = (SELECT variant_id FROM product_variants WHERE show_variant='yes' AND id=$id)";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$productVariantName = $row[0];
	
	}
	return $productVariantName;
}

function getProductVariantSurchargeById($id){
	$sql = "SELECT surcharge FROM product_variants WHERE show_variant='yes' AND id=$id";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$productVariantSurcharge = $row[0];
	
	}
	return $productVariantSurcharge;
}

function getVariantColumnById($params="*", $id){
	$sql = "SELECT $params FROM product_variants WHERE id = $id";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$variantColumnData = $row[0];
	
	}
	return $variantColumnData;
}

//end product varaint qty

//variants
function getProductVariants($product_id){
	$sql = "SELECT product_variants.id, product_variants.product_id, product_variants.variant_id, product_variants.variant_group_id, product_variants.surcharge, product_variants.qty, variants.variant_name, product_variants.show_variant FROM product_variants,variants WHERE product_variants.show_variant='yes' AND product_variants.variant_id=variants.variant_id AND product_variants.product_id='$product_id' ORDER BY variants.variant_name";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$productVariants[] = $row;
	
	}
	return $productVariants;
}

function getVariantGroups(){
	$sql = "SELECT * FROM variant_group ORDER BY group_name";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$variantGroups[] = $row;
	
	}
	return $variantGroups;
}

function getProductVariantGroups($product_id){
	$sql = "SELECT * FROM variant_group WHERE variant_group_id IN (SELECT DISTINCT variant_group_id FROM product_variants WHERE product_id='$product_id')";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$productVariantGroups[] = $row;
	
	}
	return $productVariantGroups;
}

//end variants
//cross-selling products
function getCrossSellingProducts($product_id){
	$sql = "SELECT * FROM products WHERE product_status='online' AND product_id IN (
SELECT cross_product_id FROM cross_selling_products WHERE product_id='$product_id'
) ORDER BY product_name";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$crossSellingProducts[] = $row;
	
	}
	return $crossSellingProducts;
}

function getTotalCrossSellingProducts($product_id){
	$sql = "SELECT count(product_id) FROM products WHERE product_status='online' AND product_id IN (
SELECT cross_product_id FROM cross_selling_products WHERE product_id='$product_id'
)";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalCrossSellingProducts = $row[0];
	
	}
	return $totalCrossSellingProducts;
}
//related products
function getRelatedProducts($product_id){
	$sql = "SELECT * FROM products WHERE product_status='online' AND product_id IN (
SELECT related_product_id FROM related_products WHERE product_id='$product_id'
) ORDER BY product_name";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$relatedProducts[] = $row;
	
	}
	return $relatedProducts;
}

function getTotalRelatedProducts($product_id){
	$sql = "SELECT count(product_id) FROM products WHERE product_status='online' AND product_id IN (
SELECT related_product_id FROM related_products WHERE product_id='$product_id'
)";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalRelatedProducts = $row[0];
	
	}
	return $totalRelatedProducts;
}
//get variants

//end get variants
//category
function getProductsByCategory($category_id){
	$sql = "SELECT * FROM products WHERE product_status='online' AND product_id IN (SELECT product_id FROM product_category WHERE category_id=$category_id)";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_array($results) )
	{
		$allProducts[] = $row;
	
	}
	return $allProducts;
}

function getTotalProductsByCategory($category_id){
	$sql = "SELECT count(product_id) FROM products WHERE product_status='online' AND product_id IN (SELECT product_id FROM product_category WHERE category_id=$category_id)";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_array($results) )
	{
		$totalProducts = $row[0];
	
	}
	return $totalProducts;
}

function getProductsUnderOffer(){
	$sql = "SELECT * FROM products WHERE (is_special='yes' OR is_clearence='yes' OR is_new='yes') AND product_status='online' ORDER BY product_name";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$allProducts[] = $row;
	
	}
	return $allProducts;
}

function getTotalProductsUnderOffer(){
	$sql = "SELECT count(product_id) FROM products WHERE (is_special='yes' OR is_clearence='yes' OR is_new='yes') AND product_status='online'";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$totalProducts[] = $row;
	
	}
	return $totalProducts;
}


function getNewArrivalProducts($params="*", $limit=4){
	$sql = "SELECT $params FROM products WHERE is_new = 'yes' AND product_status='online' ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$newArrivalProducts[] = $row;
	
	}
	return $newArrivalProducts;
}

function getTotalNewArrivalProducts($params="*", $limit=4){
	$sql = "SELECT count(product_id) FROM products WHERE is_new = 'yes' AND product_status='online'";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_array($results) )
	{
		$totalNewArrivalProducts = $row[0];
	
	}
	return $totalNewArrivalProducts;
}

function getNewArrivalProductsByCategory($category_id, $limit=4){
	$sql = "SELECT * FROM products WHERE is_new = 'yes' AND product_status='online' AND product_id IN (SELECT product_id FROM product_category WHERE category_id=$category_id) ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$newArrivalProducts[] = $row;
	
	}
	return $newArrivalProducts;
}

function getTotalNewArrivalProductsByCategory($category_id, $limit=4){
	$sql = "SELECT count(product_id) FROM products WHERE is_new = 'yes' AND product_status='online' AND product_id IN (SELECT product_id FROM product_category WHERE category_id=$category_id)";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_array($results) )
	{
		$totalNewArrivalProducts = $row[0];
	
	}
	return $totalNewArrivalProducts;
}
function getClearenceProducts($params="*", $limit=4){
	$sql = "SELECT $params FROM products WHERE is_clearence = 'yes' AND product_status='online' ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$clearenceProducts[] = $row;
	
	}
	return $clearenceProducts;
}

function getTotalClearenceProducts($params="*", $limit=4){
	$sql = "SELECT count(product_id) FROM products WHERE is_clearence = 'yes' AND product_status='online' ";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalClearenceProducts = $row[0];
	
	}
	return $totalClearenceProducts;
}


function getClearenceProductsByCategory($category_id, $limit=4){
	$sql = "SELECT * FROM products WHERE is_clearence = 'yes'  AND product_status='online' AND product_id IN (SELECT product_id FROM product_category WHERE category_id=$category_id) ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$clearenceProducts[] = $row;
	
	}
	return $clearenceProducts;
}

function getTotalClearenceProductsByCategory($category_id, $limit=4){
	$sql = "SELECT count(product_id) FROM products WHERE is_clearence = 'yes'  AND product_status='online' AND product_id IN (SELECT product_id FROM product_category WHERE category_id=$category_id)";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalClearenceProducts = $row[0];
	
	}
	return $totalClearenceProducts;
}

function getSpecialProducts($params="*", $limit=4){
	$sql = "SELECT $params FROM products WHERE is_special = 'yes'  AND product_status='online' ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$specialProducts[] = $row;
	
	}
	return $specialProducts;
}

function getTotalSpecialProducts(){
	$sql = "SELECT count(product_id) FROM products WHERE is_special = 'yes' AND product_status='online' ";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_array($results) )
	{
		$totalSpecialProducts = $row[0];
	
	}
	return $totalSpecialProducts;
}

function getSpecialProductsByCategory($category_id, $limit=4){
	$sql = "SELECT * FROM products WHERE is_special = 'yes'  AND product_status='online' AND product_id IN (SELECT product_id FROM product_category WHERE category_id=$category_id) ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$specialProducts[] = $row;
	
	}
	return $specialProducts;
}


function getTotalSpecialProductsByCategory($category_id){
	$sql = "SELECT count(product_id) FROM products WHERE is_featured = 'yes'  AND product_status='online' AND product_id IN (SELECT product_id FROM product_category WHERE category_id=$category_id)";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalSpecialProducts = $row[0];
	
	}
	return $totalSpecialProducts;
}
function getFeaturedProductsPHP($params="*", $limit=4){
	$sql = "SELECT $params FROM products WHERE is_featured = 'yes'  AND product_status='online' ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$featuredProducts[] = $row;
	
	}
	//return $featuredProducts;
	$smarty2 = new Smarty();

	$smarty2->template_dir = APP_ROOT.'/templates';
	$smarty2->compile_dir = APP_ROOT.'/templates_c';
	$smarty2->cache_dir = APP_ROOT.'/cache';
	$smarty2->config_dir = APP_ROOT.'/configs';
	
	$smarty2->assign('productMainImage', getProductMainImage());
	$smarty2->assign('featuredProducts',$featuredProducts);
	$smarty2->display("shop/featured_products.tpl");
	
}

function getFeaturedProducts($params="*", $limit=4){
	$sql = "SELECT $params FROM products WHERE is_featured = 'yes'  AND product_status='online' ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$featuredProducts[] = $row;
	
	}
	return $featuredProducts;
	
}
function getTotalFeaturedProducts(){
	$sql = "SELECT count(product_id) FROM products WHERE is_featured = 'yes' AND product_status='online' ";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_array($results) )
	{
		$totalFeaturedProducts = $row[0];
	
	}
	return $totalFeaturedProducts;
	
}

function getFeaturedProductsByCategory($category_id, $limit=4){
	$sql = "SELECT * FROM products WHERE is_featured = 'yes'  AND product_status='online' AND product_id IN (SELECT product_id FROM product_category WHERE category_id=$category_id) ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$featuredProducts[] = $row;
	
	}
	return $featuredProducts;
	
}

function getTotalFeaturedProductsByCategory($category_id){
	$sql = "SELECT count(product_id) FROM products WHERE is_featured = 'yes'  AND product_status='online' AND product_id IN (SELECT product_id FROM product_category WHERE category_id=$category_id)";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalFeaturedProducts = $row[0];
	
	}
	return $totalFeaturedProducts;
	
}


//by brand
function getProductsByBrand($brand_id){
	$sql = "SELECT * FROM products WHERE product_status='online' AND brand_id=$brand_id ORDER BY product_name";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_assoc($results) )
	{
		$allProducts[] = $row;
	
	}
	return $allProducts;
}

function getTotalProductsByBrand($brand_id){
	$sql = "SELECT count(product_id) FROM products WHERE product_status='online' AND brand_id=$brand_id";
	$results = mysql_query($sql);
	$total_products = mysql_num_rows($results);
	while($row = mysql_fetch_array($results) )
	{
		$totalProducts = $row[0];
	
	}
	return $totalProducts;
}
//new arrival
function getNewArrivalProductsByBrand($brand_id, $limit=4){
	$sql = "SELECT * FROM products WHERE is_new = 'yes' AND product_status='online' AND brand_id=$brand_id ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$newArrivalProducts[] = $row;
	
	}
	return $newArrivalProducts;
}

function getTotalNewArrivalProductsByBrand($brand_id){
	$sql = "SELECT count(product_id) FROM products WHERE is_new = 'yes' AND product_status='online' AND brand_id=$brand_id";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalNewArrivalProducts = $row[0];
	
	}
	return $totalNewArrivalProducts;
}

//special
function getSpecialProductsByBrand($brand_id, $limit=4){
	$sql = "SELECT * FROM products WHERE is_special = 'yes' AND product_status='online' AND brand_id=$brand_id ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$specialProducts[] = $row;
	
	}
	return $specialProducts;
}

function getTotalSpecialProductsByBrand($brand_id){
	$sql = "SELECT count(product_id) FROM products WHERE is_special = 'yes' AND product_status='online' AND brand_id=$brand_id";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalSpecialProducts = $row[0];
	
	}
	return $totalSpecialProducts;
}

//Clearence
function getClearenceProductsByBrand($brand_id, $limit=4){
	$sql = "SELECT * FROM products WHERE is_clearence = 'yes' AND product_status='online' AND brand_id=$brand_id ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$clearenceProducts[] = $row;
	
	}
	return $clearenceProducts;
}

function getTotalClearenceProductsByBrand($brand_id){
	$sql = "SELECT count(product_id) FROM products WHERE is_clearence = 'yes' AND product_status='online' AND brand_id=$brand_id";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalClearenceProducts = $row[0];
	
	}
	return $totalClearenceProducts;
}

//Featured
function getFeaturedProductsByBrand($brand_id, $limit=4){
	$sql = "SELECT * FROM products WHERE is_featured = 'yes' AND product_status='online' AND brand_id=$brand_id ORDER BY product_name LIMIT 0, $limit";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$featuredProducts[] = $row;
	
	}
	return $featuredProducts;
}

function getTotalFeaturedProductsByBrand($brand_id){
	$sql = "SELECT count(product_id) FROM products WHERE is_featured = 'yes' AND product_status='online' AND brand_id=$brand_id";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$totalFeaturedProducts = $row[0];
	
	}
	return $totalFeaturedProducts;
}
//end by brand

function getCartItems($session_id){
	$sql = "SELECT * FROM my_cart WHERE session_id = '$session_id' ORDER BY product_name";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$cartItems[] = $row;
	}
	return $cartItems;
}
function getCartProductColumnById($params="product_id", $id){
	$sql = "SELECT $params FROM my_cart WHERE id='$id'";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$cartProductColumn = $row[0];
	
	}
	return $cartProductColumn;
}
function getCartTotalItems($session_id){
	$sql = "SELECT * FROM my_cart WHERE session_id = '$session_id' ORDER BY product_name";
	$results = mysql_query($sql);
	$cartTotalItems = mysql_num_rows($results);
	
	return $cartTotalItems;
}
function getCartTotalQty($session_id){
	$sql = "SELECT SUM(product_qty) FROM my_cart WHERE session_id = '$session_id'";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$cartTotalItems = $row[0];
	}
	return $cartTotalItems;
	
}
function getCartTotalAmount($session_id){
	$sql = "SELECT sum(total) FROM my_cart WHERE session_id = '$session_id'";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$cartTotalAmount = $row[0];
	}
	
	return $cartTotalAmount;
}


function getCartItemsById($id){
	$sql = "SELECT * FROM my_cart WHERE id = $id";
	$results = mysql_query($sql);
	//$cnt_pro =0;
	while($row = mysql_fetch_assoc($results) )
	{
		$cartItemById[] = $row;
	}
	return $cartItemById;
}

function isProductInCart($product_id){
	$sql = "SELECT * FROM my_cart WHERE product_id = '$product_id'";
	$results = mysql_query($sql);
	$item_found = mysql_num_rows($results);
	if($item_found>0){
		return true;
	}else{
		return false;
	}
}
//banners
function getStoreBannerById($id){
	$sql = "SELECT * FROM store_banners WHERE banner_id=$id";
	$results = mysql_query($sql);
	while($row = mysql_fetch_assoc($results) )
	{
		$storeBannersById[] = $row;
	}
	return $storeBannersById;
}

function getStoreBanners(){
	$sql = "SELECT * FROM store_banners WHERE show_banner = 'yes'";
	$results = mysql_query($sql);
	while($row = mysql_fetch_assoc($results) )
	{
		$storeBanners[] = $row;
	}
	return $storeBanners;
}
//end banners

//shipping method

function fixedShippingRate(){
	$sql = "SELECT param_value FROM module_params WHERE module_id = (SELECT module_id FROM shipping_method where shipping_enable='yes')";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$shippingRate = $row[0];
	}
	return $shippingRate;
}

function shippingRate($totalOrderAmount){
	$sql = "SELECT class_name FROM modules WHERE module_id = (SELECT module_id FROM shipping_method where shipping_enable='yes')";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$shippingClass = $row[0];
	}
	$sql = "SELECT param_value FROM module_params WHERE module_id = (SELECT module_id FROM shipping_method where shipping_enable='yes')";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$param_value = $row[0];
	}
	
	
	
	if($shippingClass=="fixedShippingRate"){
		return $param_value;
	}elseif($shippingClass=="fixedPlusPer"){
		$prarams1 = $param_value;
		
		return $prarams1+($totalOrderAmount*10)/100;
		
	}elseif($shippingClass=="fixedPlusPerMax"){
		$prarams1 = $param_value;
		
		$val1 = ($totalOrderAmount*$param_value)/100;
		
		if($prarams1 > $val1){return $prarams1;}else{return $val1;}
	
	}elseif($shippingClass=="perOrder"){
		return ($totalOrderAmount*$param_value)/100;
	}
	
	
	//return $shippingRate;
}

//end shipping

//payment options
function getDefaultPaymentOptions(){
	$sql = "SELECT * FROM payment_options WHERE pm_id = 1";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$defaultPaymentOptions[] = $row;
	}
	
	return $defaultPaymentOptions;
}
function getPaymentInstructionsBD(){
	$sql = "SELECT bank_deposit_instructions FROM payment_options WHERE pm_id = 1";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$paymentInstructionsBD = $row[0];
	}
	
	return $paymentInstructionsBD;
}
function getPaymentInstructionsBC(){
	$sql = "SELECT money_order_instructions FROM payment_options WHERE pm_id = 1";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$paymentInstructionsBC = $row[0];
	}
	
	return $paymentInstructionsBC;
}
function getPaymentInstructionsMO(){
	$sql = "SELECT bank_check_instructions FROM payment_options WHERE pm_id = 1";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$paymentInstructionsMO = $row[0];
	}
	
	return $paymentInstructionsMO;
}
//end payments

//order
function getMaxOrderId(){
$sql = "SELECT MAX(order_id) FROM orders";
	$results = mysql_query($sql);
	while($row = mysql_fetch_array($results) )
	{
		$maxOrderId = $row[0];
	}
	
	return $maxOrderId;
}

//end order
?>
Return current item: Simple PHP Shopping cart - asaancart