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