Reputation: 7
I am trying to use a MySQL query inside my smarty template file to display the total amount pending for an affiliate payout. I believe that the code posted below is "correct" but I am just missing some part of it...
{php}
$result = select_query("tblaffiliatespending", "SUM(tblaffiliatespending.amount)", array("affiliateid" => $id), "clearingdate", "DESC", "", "tblaffiliatesaccounts ON tblaffiliatesaccounts.id=tblaffiliatespending.affaccid INNER JOIN tblhosting ON tblhosting.id=tblaffiliatesaccounts.relid INNER JOIN tblproducts ON tblproducts.id=tblhosting.packageid INNER JOIN tblclients ON tblclients.id=tblhosting.userid");
$data = mysql_fetch_array($result);
$pendingcommissions = $data[pendingcommissions];
$this->assign("pendingamount", $pendingcommissions);
{/php}
And then I have this below it to show the variable on the page:
{$pendingamount}
Whenever I load the page, it just shows a blank spot where the numbers should be...
Upvotes: 0
Views: 921
Reputation: 383
You should switch over to mysqli or PDO since mysql is deprecated as of PHP 5.5. Choosing an API.
I suppose select_query is a function you wrote yourself and am going to assume you pass the correct parameters.
$pendingcommissions = $data[pendingcommissions];
should give you an error. It should be $pendingcommissions = $data['pendingcommissions'];
instead.
If you don't get results after that try and add some debug output to check the variables you're using.
Upvotes: 0
Reputation: 224
this is a weird way to use smarty. you cannot assign a value using $this (which refers to the smarty object outside the template. in general your php which invokes smarty should assign the values to the smarty template via the smarty object. don't put application logic in smarty templates. http://www.smarty.net/docs/en/language.function.assign.tpl
fyi you can assign simple vars in smarty. but the above still applies.
Upvotes: 1