php - 在 Smarty 模板中运行 MySQL 查询

标签 php mysql smarty

我正在尝试在我的 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/

相关文章:

php - 如何在 PHP 中快速开发 MySQL 表的可排序、分页数据网格?

mysql - 如何使用 Like 运算符在 Mysql 中不显示重复值?

php - 使用Smarty,是否可以根据方法的返回值调用方法?

php - 从 MySQL 返回一行

php - 使用 JQuery 和 CodeIgniter 将注释安全地写入数据库?

php - MySql/PHP 插入 SET Last_Insert_ID()

javascript - 从另一个ajax函数获取json编码数据

mysql - 如何使用 mysql 查询批量编辑 meta_value

MySQL - 选择多个最大值

php - Smarty Foreach 循环将 +1 添加到它打印出的类