gpt4 book ai didi

PHP + Smarty + MySQL

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:43 26 4
gpt4 key购买 nike

请帮帮我!如何将数据从表传输到 smarty?

功能:

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

索引.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}

最佳答案

您的getBanLog() 函数不返回任何内容,需要添加一个返回语句。另外 $result = $query = $mysqli->.. 也不正确。

试试这个

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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17897644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com