What is the correct method to wrap a heap of code into a variable
===

I'm working with a shopping cart script that doesn't let me add php to the template files. The method used is to create $GLOBALS within the class files and call them from the tpl files. What i need to do if the following. <br>
$GLOBALS['DiscountedPrice'] need to be equal to that chuck of code that follows. I've tried a few syntax options to try and wrap it up, but it breaks because the same syntax is used inside the chuck of code. <br>
Any help appreciated.<br>Thanks

    $GLOBALS['DiscountedPrice'] =  $query = mysql_query("
    		     SELECT *
    		     FROM isc_customer_group_discounts
    		     WHERE `catorprodid` = '%%GLOBAL_ProductId%%'
    		     AND `customergroupid` = 1
    		     AND `discounttype` = 'PRODUCT'
    		     ");
    $discounted_price = '';
    while($proddisc = mysql_fetch_array($query)) {
    	$discperc = $proddisc['4'];
    	$discmeth = $proddisc['6'];
    	if($discmeth = 'percent') {
    		$discperc = $proddisc['4']/100;
    		$discounted_price = $row['prodprice'] * $discperc;
    		$GLOBALS['DiscountedPrice'] = $discounted_price;
    	}elseif ($discmeth = 'price') {
    		$discounted_price = $row['prodprice'] - $discperc;
    		$GLOBALS['DiscountedPrice'] = $discounted_price;
    	}elseif ($discmeth = 'fixed') {
    		$discounted_price = $discperc;
    		$GLOBALS['DiscountedPrice'] = $discounted_price;
    	}};


