当前位置: 动力学知识库 > 问答 > 编程问答 >

PHP MySQL clear query

问题描述:

Currently, when the user logs in, the query automatically runs and prints data to the screen. I want the screen to be blank on the initial login, however.

Here is my PHP function that calls the data:

<?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";

}

}

?>

What do I need to add so that this query doesn't execute upon the initial login? In addition, how would I add a reset button?

Thank you in advance.

网友答案:

You could use and check a session variable. 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;
分享给朋友:
您可能感兴趣的文章:
随机阅读: