bristolspider 0 Newbie Poster

i have to the following code which give u a cost price(thats our price) and a RRP i have made it work the difrence out and put its as a % but cant get it to show anything other than "£0" for saving have i missed somthing

<?php

		$_REQUEST['type'] = explode("-", $_REQUEST['type']);
		$_REQUEST['type'] =  $_REQUEST['type'][0];
if (!$_REQUEST['type']) { $_REQUEST['type'] = "zero"; }
if ($_REQUEST['type']) {
	if ($_REQUEST['type'] == "zero") { $_REQUEST['type'] = 0; }
	//Sub Product type
	$i = 0;
	$result = $myDB->query_select("SELECT * FROM " . $config['table_product_types'] . " WHERE parent = " . $_REQUEST['type'] . " ORDER BY Id ASC");
	
	while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {	
		$dataa[$i][Id]			=	 $row['Id'];	

		$dataa[$i][descrip]		=	$row['descrip'];
		$dataa[$i][image]		=	"images/product_types/" . $row['image'];
		$dataa[$i][imagecl]		=	$row['image'];

		$dataa[$i][name]		=	str_replace("\"", "&quot;", $row['name']);

		$dataa[$i][name]		=	str_replace("'", "&acute;", $dataa[$i][name]);
		$dataa[$i][name]		=	str_replace("&", "&#38;", $dataa[$i][name]);		
		$dataa[$i][name] = str_replace("-", " ", $dataa[$i][name]);
	$dataa[$i][name]		=	str_replace("/", "&#47;", $dataa[$i][name]);	
		$dataa[$i][plink]		=	"category-" . $dataa[$i][Id] . "-" . str_replace("&#47;", "-", $dataa[$i][name]) . "-1.html";

		if ((!$row['image']) || (!is_file($dataa[$i][image]))) {
			$dataa[$i][image] = $dataa[$i][name];
		} else {
			$dataa[$i][image] = "<img src='images/product_types/" . $row['image'] . "' style='border:none'>";
		}
		
		$wharray[$i] = $G->scaleimage("./images/product_types/" . $row['image'], $config['maxpindeximgw'], $config['maxpindeximgh']);
		$dataa[$i][imageh]		=	$wharray[$i]['h'];
		$dataa[$i][imagew]		=	$wharray[$i]['w'];
		$i++;
	}
} else {
	die("error :");
}

	if ((!$_REQUEST['from']) && (!$_REQUEST['to'])){
		//gets total products
		$result = $myDB->query_select("SELECT * FROM " . $config['table_product_types'] . " WHERE Id = '" . $_REQUEST['type'] . "'");
		$row = mysql_fetch_array($result,MYSQL_ASSOC);
		$total = $row['products'];
	} else {


		$result = $myDB->query_select("SELECT * FROM " . $config['table_products'] . " 
		WHERE type = {$_REQUEST['type']} && cost > {$_REQUEST['from']} && cost < {$_REQUEST['to']}");

		$total = mysql_num_rows($result);
		
	}
	$_REQUEST['ptitle'] = str_replace(" ", "-", $_REQUEST['ptitle']);
	
//$total = $myItems->getTotalProducts($_REQUEST['type']);
$pages = new pagination($config['p_limit'], $_REQUEST['page'], $total, "category-" .  $_REQUEST['type'] . "-" . $_REQUEST['ptitle'] . "", $_REQUEST['from'], $_REQUEST['to']);
$main_start = $pages->return_pagestart();
$products = $myItems->getAll("type", $_REQUEST['type'], $main_start, '', $_REQUEST['to'], $_REQUEST['from']);	// Gets all the items from the database (need to check speed)

$pagetpl = new template; 			//Creates a new instance of the template class for this page
$pagetpl->set_template($page_url, "[", "]"); 	//Sets the tpl (template) file and the prefix and sufix characters

for ($i = 0; $i < sizeof($products); $i++) {
		$products[$i]['fullname'] = $products[$i]['name'];
		$products[$i]['saving'] = $products[$i]['rrp'] - $products[$i]['cost'];
		$products[$i]['name'] = substr($products[$i]['name'], 0, 25);
		$products[$i]['fuldescrip'] = $products[$i]['descrip'];
		$products[$i]['descrip'] = substr($products[$i]['descrip'], 0, 40) . "...";
		if ((empty($products[$i]['firstimage'])) || (!is_file("images/products/" . $products[$i]['firstimage']))) {
			$products[$i]['firstimage'] = "{SKINDIR}/no_image.gif";	
		} else {
			$products[$i]['firstimage'] = "images/products/" . $products[$i]['firstimage'];
			$firstimagesizes[$i] = $C->scaleimage($products[$i]['firstimage'], $config['maxpindeximgw'], $config['maxpindeximgh']);
			$products[$i]['firstimagew'] = $firstimagesizes[$i]['w'];
			$products[$i]['firstimageh'] = $firstimagesizes[$i]['h'];
		}
		
		###### LINK ######
		$products[$i]['urlname']		=	str_replace("\"", "&quot;", $products[$i]['fullname']);
		$products[$i]['urlname']	=	str_replace("'", "&acute;", $products[$i]['urlname']);
		$products[$i]['urlname']		=	str_replace("&", "&#38;", $products[$i]['urlname']);		
		$products[$i]['urlname']	= 	str_replace(" ", "-", $products[$i]['urlname']);	
	$products[$i]['itemlink'] = "product-" . $products[$i]['pid'] . "-" . $products[$i]['urlname'] . ".html";
		##################
	if (($products[$i]['rrp'] > 0) && ($products[$i]['rrp'] != "0.00")){
		$products[$i]['saving'] = $row['rrp'] - $row['cost'];
		$savings = ($products[$i]['rrp'] - $products[$i]['cost']);
		$percent = round( ($savings/$products[$i]['rrp'])*100);
		$products[$i]['percent'] = $percent;
	} else {
		$products[$i]['percent'] = "N/A";
		$products[$i]['saving'] = "N/A";
		$products[$i]['rrp'] = "N/A";
	}
	if ($products[$i]['saleprice'] > "0.00") {
		$products[$i]['saleprice'] = "<font color=\"#990000\">Sale Price: " . $products[$i]['saleprice'] . "</font>";
	} else {
		$products[$i]['saleprice'] = "";
	}
}

//Theses are all the varibles that we can use in the tpl file.
$pagetpl->set_var('TITLE',	$_REQUEST['ptitle'], 	'');  
$pagetpl->set_var('SKINDIR', './templates/' . $config['skin_id'] . '/images');
  
$pagetpl->set_var('products',	$products, 	''); 
$pagetpl->set_var('TOTALPRODUCTS',	$total, 	''); 
$pagetpl->set_var('PLINKS',	$pages->draw_links(), 	'');    
$pagetpl->set_var('productssize', $C->sizeofarray($products), '', TRUE);	//sets up the empty cart if statement
$pagetpl->set_var('PTYPEIMG',					$_REQUEST['timage']);
$pagetpl->set_var('USERID',		$user_id); 
$pagetpl->set_var('loggedin', 	$C->logictest($user_id), '', TRUE);	//if statement

$pagetpl->set_var('subplist', $dataa, '');
$pagetpl->set_var('subplsize', $C->sizeofarray($dataa), '', TRUE);	//sets up the empty cart if statement

//This draw the page with all its changes to the screen.
$pagetpl->parse();
$content =  $pagetpl->draw();
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.