-3

目前,当用户登录时,查询会自动运行并将数据打印到屏幕上。但是,我希望在初始登录时屏幕为空白。

这是我调用数据的 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";
    }
}

?>

我需要添加什么才能使此查询在初始登录时不执行?另外,我将如何添加一个重置按钮?

先感谢您。

4

1 回答 1

1

您可以使用并检查会话变量。IE

//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;
于 2013-08-01T13:13:23.767 回答