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;
}

PHP + Smarty + MySQL的更多相关文章

  1. 0810 smarty

    1.Smarty简介(why,what) why:smarrty 将前端工程师和程序员的工作分开,让前端工程师完成前台页面的工作,程序员完成后台的业务逻辑.what模版引擎是用来将PHP代码和模版页组 ...

  2. 《实战突击:PHP项目开发案例整合(第2版)(含DVD光盘1张)》

    <实战突击:PHP项目开发案例整合(第2版)(含DVD光盘1张)> 基本信息 作者: 徐康明    辛洪郁 出版社:电子工业出版社 ISBN:9787121221378 上架时间:2014 ...

  3. php+mysql+smarty+oop

    php+mysql+smarty+oop 设计新闻系统简单的UML模 powerdesigner和diagram designer 设计所需环境.模块.模板样式 数据库uml设计和创建数据库结构 db ...

  4. PHP+MySQL Smarty简单分页显示示例

    一.分页程序的原理 分页程序有两个非常重要的参数:每页显示几条记录($pagesize)和当前是第几页($page). 有了这两个参数就可以很方便的写出分页程序,我们以MySql数据库作为数据源,在m ...

  5. PHP中smarty与MYSQL数据库的连接

    进行与MYSQL数据库的关联 先从最简单的数据库查询语句开始 1.先创建mysql数据库 仅仅创建一个测试数据 2.引用smarty框架 3.按照上文在damo文件夹下创建smarty_inc.php ...

  6. ajax结合mysql数据库和smarty实现局部数据状态的刷新

    效果状态:通过点击锁定状态实现状态锁定与不锁定之间的切换 1.主程序:01.php导入smarty和mysql类,取得数据导入列表模板 <?php    include './include/M ...

  7. php手册 | python手册 | perl手册 | c#.net手册 | c++手册 | ruby手册 | jquery手册 | js手册 | prototype手册 | mysql手册 | smarty手册 | css手册 | html手册 | nginx手册 | apache手册 | shell手册 | svn手册

    收集各种实用类手册: http://shouce.jb51.net/shell/

  8. 12月15日smarty模板基本语法

    smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...

  9. smarty 模板的入门使用

    <?php require_once 'inc/libs/Smarty.class.php'; $s=new Smarty(); // echo $s::SMARTY_VERSION; // e ...

随机推荐

  1. InnoDB引擎中的索引与算法9

    5.1 InnoDB支持以下几种常见的索引: B+树索引 全文索引 哈希索引(自适应哈希索引) 关于哈希索引的说明: -- 1.InnoDB的哈希索引是自适应的,其根据表的使用情况自动生成哈希索引,不 ...

  2. Scyther GUI 攻击输出图的解释

    1.在声明事件的安全属性的时候也就是整个过程要验证的 对象: Scythe 的安全属性  分为下面几种: Secrecy: 表示数据传输过程中是安全的,即使通过不信任的网络传也不能被攻击者获得 SKR ...

  3. (13)input输入函数

    (1)input 等待用户动态输入一个值,注意得到的值是一个字符串类型 提示用户输入用户名和密码: 如果用户名是admin , 并且密码是000 , 提示用户恭喜你,登陆成功 否则提示用户名或密码错误 ...

  4. 使用pyinstaller打包使用cx_Oracle模块的程序出现The specified module could not be found的问题

    pyinstaller看起来并不会将动态链接库自动打包,所以我们需要告诉pyinstaller要打包哪些动态链接库,步骤如下(假设python文件名为 oracletest.py): 1. 使用pyi ...

  5. idea在springboot项目中显示Run Dashboard

    1.Run->Edit Configurations 2.在Templates[Defaults]-> Configurations available in Run Dashboard ...

  6. 表单文本字段预期描述(placeholder="请输入产品名称"以及prompt:'输入价格')

    普通html文本标签设置: <input id="xxx" placeholder="请输入产品名称"/> 带有jQueryEasyUI插件的htm ...

  7. 001_STM32程序移植之_DS1302

    1. 测试环境:STM32C8T6 2. 测试模块:DS1302时钟模块 3. 测试接口: 1. DS1302模块接口: DS1302引脚 单片机引脚 VCC--------------------3 ...

  8. Laravel API Errors and Exceptions: How to Return Responses

    Laravel API Errors and Exceptions: How to Return Responses February 13, 2019 API-based projects are ...

  9. oracle数据库GROUP BY 子句

    1.GROUP BY子句 在SELECT 列表中所有未包含在组函数中的列都应该包含在GROUP BY 子句中. 如下: SELECT deptno,AVG(sal) from emp GROUP BY ...

  10. loj#6285 数列分块入门 9 ( 回 滚 )

    题目 :  链接 :https://loj.ac/problem/6285 题意:给出一个长为 n的数列,以及 n个操作,操作涉及询问区间的最小众数. 思路:虽然这不是一道 回滚莫队题,就是 暴力分块 ...