I have created the following function in php. I want to call it from a smarty file, but I keep getting an error from the smarty. What am i doing wrong?
<?php
function getCommission($inputid)
{
$database="xxxxxxxxxxxxxx";
mysql_connect (xxxxxxxxxxxxxxxxx);
@mysql_select_db($database) or die( "Unable to select database");
$data = mysql_query("SELECT * FROM hb_aff WHERE id = $inputid")
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
return $info['total_commissions'];
}
}
?>
Part of the tpl code is:
{include file="getCommission"}
<tr>
<td >{$lang.convrate}</td>
<td >{$affiliate.conversion} %</td>
<td >{$lang.commissions}</td>
<td ><input size="3" value="{getCommission($affiliate.id}" name="total_commissions"/></td>
</tr>
I think you missed a parenthesis here before the last accolade :
"{getCommission($affiliate.id}"
You first need to register the function with Smarty, rather than using {include}
:
<?php
$smarty->registerPlugin("function","getCommission", "getCommission");