PHP MySQL清除查询
当前,当用户登录时,查询将自动运行并将数据打印到屏幕上。但是,我希望在初次登录时屏幕是空白的 下面是调用数据的PHP函数:PHP MySQL清除查询,php,mysql,Php,Mysql,当前,当用户登录时,查询将自动运行并将数据打印到屏幕上。但是,我希望在初次登录时屏幕是空白的 下面是调用数据的PHP函数: <?php function displayrecords() { $groups = $_POST['mygroup']; $type = $_POST['mytype']; $service = $_POST['myservice']; $sql_json = "SELECT * FROM mytable"; $where
<?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";
}
}
?>
您可以使用并检查会话变量。i、 e
//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;
你的问题需要更加精确。您可以很容易地不调用该函数,并且它将永远不会执行,从而使初始登录屏幕为空代码>在函数开始时;但之后该功能不再工作。必须有一些php代码,比如:if(login==initialLogin){don'tcall function};如果一个人是初次登录,在数据库中存储一个值。首次登录后更新字段