PHP + Smarty + MySQL
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}
- 1code looks fine whats the problem ? – M Khalid Junaid Jul 27 '13 at 12:10
- Only thing suspect here is the lack of a
WHEREclause in your query, which appears to return all bans for all users, not just the user as implied by theUserInfo(). – 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的更多相关文章
- 0810 smarty
1.Smarty简介(why,what) why:smarrty 将前端工程师和程序员的工作分开,让前端工程师完成前台页面的工作,程序员完成后台的业务逻辑.what模版引擎是用来将PHP代码和模版页组 ...
- 《实战突击:PHP项目开发案例整合(第2版)(含DVD光盘1张)》
<实战突击:PHP项目开发案例整合(第2版)(含DVD光盘1张)> 基本信息 作者: 徐康明 辛洪郁 出版社:电子工业出版社 ISBN:9787121221378 上架时间:2014 ...
- php+mysql+smarty+oop
php+mysql+smarty+oop 设计新闻系统简单的UML模 powerdesigner和diagram designer 设计所需环境.模块.模板样式 数据库uml设计和创建数据库结构 db ...
- PHP+MySQL Smarty简单分页显示示例
一.分页程序的原理 分页程序有两个非常重要的参数:每页显示几条记录($pagesize)和当前是第几页($page). 有了这两个参数就可以很方便的写出分页程序,我们以MySql数据库作为数据源,在m ...
- PHP中smarty与MYSQL数据库的连接
进行与MYSQL数据库的关联 先从最简单的数据库查询语句开始 1.先创建mysql数据库 仅仅创建一个测试数据 2.引用smarty框架 3.按照上文在damo文件夹下创建smarty_inc.php ...
- ajax结合mysql数据库和smarty实现局部数据状态的刷新
效果状态:通过点击锁定状态实现状态锁定与不锁定之间的切换 1.主程序:01.php导入smarty和mysql类,取得数据导入列表模板 <?php include './include/M ...
- php手册 | python手册 | perl手册 | c#.net手册 | c++手册 | ruby手册 | jquery手册 | js手册 | prototype手册 | mysql手册 | smarty手册 | css手册 | html手册 | nginx手册 | apache手册 | shell手册 | svn手册
收集各种实用类手册: http://shouce.jb51.net/shell/
- 12月15日smarty模板基本语法
smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...
- smarty 模板的入门使用
<?php require_once 'inc/libs/Smarty.class.php'; $s=new Smarty(); // echo $s::SMARTY_VERSION; // e ...
随机推荐
- TLS1.3&TLS1.2形式化分析(二)
1.下面是TLS1.2和TLS1.3握手协议过程 ,明显的可以看出存在不同 . 我们先说TLS1.2的握手过程明显是比TLS1.3的握手过多了一次.在TLS1.3中舍弃了之前RSA的协商过程,然后基于 ...
- Nginx系列1.1:ubuntu16.04编译nginx-rtmp流媒体服务器
1.下载nginx和nginx-rtmp-module nginx官网:nginx.org tar.gz文件 解压缩命令: wget https://nginx.org/download/nginx- ...
- RT-Thread--时间管理
时钟节拍 时钟节拍是特定的周期中断,可以看是系统心跳,中断之间的时间间隔取决于不同的应用,一般是 1ms–100ms,时钟节拍率越快,系统的额外开销就越大,从系统启动开始计数的时钟节拍数称为系统时间. ...
- 1115 JAVAScript基础
目录 JavaScript 1.基础 1.1 注释 1.2 引入方式 2. 变量 2.1 变量声明 2.2 变量的命名规范 3.常量 4. 数据类型 4.1 数值型 Number 4.2 字符串型 S ...
- Hibernate初探之单表映射——第二章:Hibernate进阶
第二章:Hibernate进阶 1.hibernate.cfg.xml常用配置 2.session 简介 3.transaction简介 4.session详解 5.对象关系映射常用配置 1.hibe ...
- Python+request+ smtplib 测试结果html报告邮件发送(下)《六》
目录结构如下: 1.cfg.ini的配置信息写法如下: [email] ;--------------------------使用腾讯企业邮箱作为发件人的操作如下------------------- ...
- PL/SQL老是自动断开问题处理
问题背景:情况是这样的,很多开发同事的plsql上班时间开着8个小时,有时候他们出去抽烟后或者中午吃完饭,回来在plsql上面执行就报错无响应,然后卡住了半天动弹不了,非得重新登录plsql才生效,我 ...
- Google-Guava Concurrent包里的Service框架浅析
原文地址 译文地址 译者:何一昕 校对:方腾飞 概述 Guava包里的Service接口用于封装一个服务对象的运行状态.包括start和stop等方法.例如web服务器,RPC服务器.计时器等可以实 ...
- [ES2019] Use JavaScript ES2019 flatMap to Map and Filter an Array
ES2019 introduces the Array.prototype.flatMap method. In this lesson, we'll investigate a common use ...
- Python 2--序列