我正在尝试在我的 smarty 模板文件中使用 MySQL 查询来显示联属网络营销待支付的总金额。我相信下面发布的代码是“正确的”,但我只是遗漏了其中的一部分......
{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}
然后我在其下面显示了页面上的变量:
{$pendingamount}
每当我加载页面时,它只会显示一个空白位置,其中的数字应该是...
最佳答案
这是一种奇怪的使用 smarty 的方式。你不能使用 $this 赋值(它指的是模板外部的 smarty 对象。一般来说,调用 smarty 的 php 应该通过 smarty 对象将值分配给 smarty 模板。不要将应用程序逻辑放在 smarty 模板中。 http://www.smarty.net/docs/en/language.function.assign.tpl
仅供引用,您可以在 smarty 中分配简单的变量。但上述内容仍然适用。
关于php - 在 Smarty 模板中运行 MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22122315/