javascript 单击搜索按钮后如何显示搜索详细信息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10716593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display search details after search button is clicked?
提问by user1394925
I have a modal window where it contains a textbox and a search button. Now what I want is that when the user enters in a word and then clicks on the "Search" button, I want it to run the query and display the results wether there is a result or not.
我有一个模态窗口,其中包含一个文本框和一个搜索按钮。现在我想要的是,当用户输入一个词然后单击“搜索”按钮时,我希望它运行查询并显示结果,无论是否有结果。
The problem is that I don't know how to get the "Search" button to output the neccessary details after it has been cliked. At the moment if the user clicks on the "Search" button after typing in a word, nothing happens.
问题是我不知道如何让“搜索”按钮在点击后输出必要的详细信息。目前,如果用户在输入单词后单击“搜索”按钮,则什么也不会发生。
So I want just a normal function associated with the "Search" button so that it outputs the details after the search button has been clicked. How can this be achieved?
所以我只想要一个与“搜索”按钮相关的普通功能,以便在点击搜索按钮后输出详细信息。如何做到这一点?
Here is a link to the applicationso you can see what is happening.
这是该应用程序的链接,您可以查看正在发生的事情。
Below is the full code:
下面是完整的代码:
<div class="previouslink">
<button type="button" id="close" onclick="return closewindow();">Close</button>
<h1>PREVIOUS QUESTIONS</h1>
<?php
foreach (array('questioncontent') as $varname) {
$questioncontent = (isset($_POST[$varname])) ? $_POST[$varname] : '';
}
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<p>Search: <input type="text" name="questioncontent" value="<?php echo $questioncontent; ?>" /></p>
<p><input id="searchquestion" name="searchQuestion" type="submit" value="Search" /></p>
</form>
<?php
if (isset($_POST['searchQuestion'])) {
$questionquery = "SELECT QuestionContent FROM Question
WHERE(QuestionContent = '".mysql_real_escape_string($questioncontent)."')";
$questionnum = mysql_num_rows($questionresult = mysql_query($questionquery));
?>
<p>
Your Search: <?php echo "'$questioncontent'"; ?>
</p>
<?php
if($questionnum ==0){
echo "<p>Number of Questions Shown from the Search: <strong>$questionnum</strong></p>";
echo "<p>Sorry, No Questions were found from this Search</p>";}
else{
echo"<p>Number of Questions Shown from the Search: <strong>$num</strong></p>";
$output = "";
$output .= "
<table border='1'>
<tr>
<th>Question</th>
</tr>
";
while ($questionrow = mysql_fetch_array($questionresult)) {
$output .= "
<tr>
<td>{$questionrow['QuestionContent']}</td>
</tr>";
}
$output .= " </table>";
echo $output;
}
if (empty($questioncontent)){
echo "Please enter in a phrase in the text box in able to search for a question";
}
}
mysql_close();
?>
</div>
UPDATE BELOW:
更新如下:
<body>
<?php
if (isset($_POST['searchQuestion'])) {
echo "xxx";
exit;
}
?>
<form id="QandA" action="imageupload.php" method="post">
<h1>CREATING QUESTIONS AND ANSWERS</h1>
<table id="plus" align="center">
<tr>
<th>
<a onclick="return plusbutton();">
<img src="Images/plussign.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage"/>
</a>
<span id="plussignmsg">(Click Plus Sign to look <br/> up Previous Questions)</span>
</th>
</tr>
</table>
<div class="previouslink">
<button type="button" id="close" onclick="return closewindow();">Close</button>
<h1>PREVIOUS QUESTIONS</h1>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<p>Search: <input type="text" name="questioncontent" /></p>
<p><input id="searchquestion" name="searchQuestion" type="submit" value="Search" /></p>
</form>
</div>
</form>
</body>
回答by Vishal
You should move your input tags inside a <form method="POST"> </form>
block.
您应该将输入标签移动到一个<form method="POST"> </form>
块内。
回答by Rinzler
Try to debug what you are getting on clicking button search use exit see what your query is listing ,
尝试调试您在单击按钮搜索时获得的内容,使用退出查看您的查询正在列出的内容,
when there is no form no action so nothing will happen on clicking search use proper code formatting
当没有表单时没有操作所以点击搜索时不会发生任何事情使用正确的代码格式