0
請幫助我!如何將數據從表格傳輸到smarty?PHP + Smarty + MySQL
功能:
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}
代碼看起來不錯什麼問題呢? –
這裏唯一值得懷疑的是查詢中缺少'WHERE'子句,它似乎會爲所有用戶返回所有禁令,而不僅僅是UserInfo()所隱含的用戶。 –
@dianuj'getBanLog()'不返回任何內容,並且'$ result = $ query = $ mysqli-> query' – bansi