目前,当用户登录时,查询会自动运行并将数据打印到屏幕上。我希望在初次登录时屏幕为空白。
这是我调用数据的PHP函数:
<?php
function displayrecords() {
$groups = $_POST['mygroup'];
$type = $_POST['mytype'];
$service = $_POST['myservice'];
$sql_json = "SELECT * FROM mytable";
$where = "";
if ($groups != "") {
$where = " `mygroup` = '" . mysql_real_escape_string($groups) . "'";
}
if ($type != "") {
if ($where != "")
$where .= " AND ";
$where .= " `mytype` = '" . mysql_real_escape_string($type) . "'";
}
if ($service != "") {
if ($where != "")
$where .= " AND ";
$where .= " `myservice` = '" . mysql_real_escape_string($service) . "'";
}
if ($where != "")
$sql_json = $sql_json . " WHERE " . $where . ";";
$QueryResult = @mysql_query($sql_json) or die(mysql_error());
echo "<table class='table table-striped table-bordered table-hover'>\n";
echo "<tr><th>ID</th>" . "<th>Group</th><th>Type</th>" .
"<th>Service</th>" . "<th>Description</th></tr>\n";
while (($Row = mysql_fetch_assoc($QueryResult)) !== FALSE) {
echo "<tr><td>{$Row[pk_tId]}</td>";
echo "<td>{$Row[mygroup]}</td>";
echo "<td>{$Row[mytype]}</td>";
echo "<td>{$Row[myservice]}</td>";
echo "<td>{$Row[mydescription]}</td>
</tr>\n";
};
echo "</table>\n";
if (mysql_num_rows($QueryResult) == 0) {
echo "No results";
}
}
?>
我需要添加什么才能在初次登录时执行此查询?另外,我如何添加重置按钮?
提前谢谢。
答案 0 :(得分:1)
您可以使用并检查会话变量。即。
//In your authentication method
$_SESSION['INITIAL_LOAD'] = true;
//In the code you provided above
if (!$_SESSION['INITIAL_LOAD']) {
// run the query stuff
}
// At the end of the page
$_SESSION['INITIAL_LOAD'] = false;