有人可以解释如何在HTML模板中的不同位置显示不同的变量吗?我希望标题中的$row['fullname']
和右侧边栏中的另一个变量?谢谢!我读到了全局变量,但我现在避免使用全局变量。如果我为功能添加新参数是否可行? (我不这么认为)
function viewMember($mysqli, $member)
{
$ret = "";
$statement = $mysqli->query(
"SELECT * FROM members WHERE username = '$member' "
);
$row = $statement->fetch_array();
$ret = $ret . 'User ID:' . htmlentities($row['id']) . '</br>
Full Name: ' . htmlentities($row['fullname']) . '</br>
Username: ' . htmlentities($row['username']) . '</br>
Email: ' . htmlentities($row['email']) . ' </br>
Last Login: ' . htmlentities($row['last_online']) . '</br>
Last IP: ' . htmlentities($row['last_ip']) . '<br/>
Last Browser: ' . htmlentities($row['http_agent']) . '<br/>
System Role : ' . htmlentities($row['role']) . '';
return $ret;
}
答案 0 :(得分:0)
Hope this will help you!
<?php
session_start();
function viewMember($mysqli,$member)
{
$ret = "";
$statement = $mysqli->query("SELECT * FROM members WHERE username = '$member' ");
$row = $statement->fetch_array();
$ret =
$ret.'User ID:'.htmlentities($row['id']).' </br>
Full Name: ' .htmlentities($row['fullname']).'</br>
Username: ' .htmlentities($row['username']).'</br>
Email: ' .htmlentities($row['email']).' </br>
Last Login: '.htmlentities($row['last_online']).'</br>
Last IP: ' .htmlentities($row['last_ip']).'<br/>
Last Browser: '.htmlentities($row['http_agent']).'<br/>
System Role : '.htmlentities($row['role']).'';
$_SESSION['id']=htmlentities($row['id']);
$_SESSION['fullname']=htmlentities($row['fullname']);
$_SESSION['username']=htmlentities($row['username']);
$_SESSION['email']=htmlentities($row['email']);
$_SESSION['last_online']=htmlentities($row['last_online']);
$_SESSION['last_ip']= htmlentities($row['last_ip']);
$_SESSION['http_agent']=htmlentities($row['http_agent']);
$_SESSION['role']= htmlentities($row['role']);
return $ret;
}
?>
// Echo following variables wherever you want
$_SESSION['id'];
$_SESSION['fullname'];
$_SESSION['username'];
$_SESSION['email'];
$_SESSION['last_online'];
$_SESSION['last_ip'];
$_SESSION['http_agent'];
$_SESSION['role'];