Help me please! How to transfer data from table to smarty?

Function:

public function getBanLog() {
global $mysqli;
$result = $query = $mysqli->query("SELECT * FROM `bans`") or die($mysqli->error);
$rows = array();
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
$rows[] = $row;
}
}

index.php:

$user = new UserInfo();
$smarty = new Smarty(); $smarty->assign("userInfo", $user);
$smarty->assign('ban', $user->getBanLog());
$smarty->display('template/ban.tpl');

ban.tpl:

{foreach from=$ban item=row}
<td>{$row.id}</td>
<td>{$row.banned}</td>
<td>{$row.admin}</td>
<td>{$row.reason}</td>
{/foreach}
asked Jul 27 '13 at 12:08
  • 1
    code looks fine whats the problem ? – M Khalid Junaid Jul 27 '13 at 12:10
  •  
    Only thing suspect here is the lack of a WHERE clause in your query, which appears to return all bans for all users, not just the user as implied by the UserInfo(). – Michael Berkowski Jul 27 '13 at 12:11
  •  
    @dianuj getBanLog() returns nothing, and $result = $query = $mysqli->query – bansi Jul 27 '13 at 12:14 

Your getBanLog() function returns nothing, need to add a return statement. Also $result = $query = $mysqli->.. is not correct.

Try this

public function getBanLog() {
global $mysqli;
$result = $mysqli->query("SELECT * FROM `bans`") or die($mysqli->error);
$rows = array();
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
$rows[] = $row;
}
return $rows;
}

最新文章

  1. .net(c#)版RSA加密算法,拿走不谢
  2. Java程序日志:java.util.logging.Logger类
  3. WPS 从今以后我再也不会用了 记录一下!
  4. javascript高级程序设计---DOM
  5. jquery单选框radio值改变change事件
  6. linux 常用命令大全
  7. 使用Eclipse Installer安装Eclipse
  8. CF 241E flights 最短路,重复迭代直到稳定 难度:3
  9. 判断一个Bitmap图像是否是.9图
  10. HDOJ/HDU 2140 Michael Scofield&#39;s letter(字符转换~)
  11. 日志管理-将Log4net的配置配置到的独立文件中
  12. JavaScript对象的valueOf()方法
  13. python 方法
  14. virtualBox安装centos,并搭建tomcat
  15. React对比Vue(05 生命周期的对比)
  16. MapReduce计算之——hadoop中的Hello World
  17. Nginx 负载均衡的几种方式
  18. PHP:第三章——PHP中的回调函数
  19. Oracle EBS 锁
  20. SRM 624 D2L3: GameOfSegments, 博弈论,Sprague–Grundy theorem,Nimber

热门文章

  1. javascript中如何判断数组是数组
  2. Python多线程爬虫爬取网页图片
  3. 2BIT
  4. hive的shell用法(脑子糊涂了,对着脚本第一行是 #!/bin/sh 疯狂执行hive -f 结果报错)
  5. JAVA遇见HTML——JSP篇(2、JSP基础语法)
  6. Web应用中的缓存一致性问题
  7. mysql中对表操作----为所有列插入数据
  8. idea在springboot项目中显示Run Dashboard
  9. tableviewer自动调整列宽
  10. 从 ES6 到 ES10 的新特性万字大总结