【问题标题】:How to display search details after search button is clicked?单击搜索按钮后如何显示搜索详细信息?
【发布时间】:2012-05-29 19:17:12
【问题描述】:

我有一个模式窗口,其中包含一个文本框和一个搜索按钮。现在我想要的是,当用户输入一个单词然后单击“搜索”按钮时,我希望它运行查询并显示结果,无论是否有结果。

问题是我不知道如何让“搜索”按钮在被点击后输出必要的详细信息。目前,如果用户在输入单词后单击“搜索”按钮,则没有任何反应。

所以我只想要一个与“搜索”按钮关联的普通功能,以便在单击搜索按钮后输出详细信息。如何实现?

这是application 的链接,您可以查看正在发生的事情。

以下是完整代码:

<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>

以下更新:

<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>

【问题讨论】:

  • 现在尝试运行你的 php,如果在页面顶部提交代码,它总是在顶部而不是在调用表单中,就像我更新了你的问题

标签: php javascript ajax dom button


【解决方案1】:

尝试调试您在单击按钮搜索时得到的内容,使用退出查看您的查询列出的内容,

当没有表单时没有任何动作,所以点击搜索不会发生任何事情,使用正确的代码格式

【讨论】:

  • 我没有从错误控制台得到任何错误,我已经更新了代码,但仍然没有显示任何细节。我不仅仅是在谈论来自查询的结果,我还在谈论如果它没有找到结果,它就不会显示消息。我已经包含了表单标签和操作方法,但仍然没有
  • 尝试退出;首先看看点击搜索是否可以打印一个hello world。我认为问题是控制没有通过你是否使用了正确的 html 标签表单没有 没有人会为你调试首先检查哪里是传递提交的控件
  • 所有的 html 标签都在正确的位置。请问一下exit命令怎么用?是 php 还是 javascript 命令?
  • 我知道你是完全的初学者。它的 php 用于调试,直到您的控件在哪里通过以及您在哪一行出现错误。在这一行 if (isset($_POST['searchQuestion'])) { //添加此代码并查看是否打印 echo "xxx";出口; }
  • 如果您查看问题的底部,我已经提到了下面的更新,以表明我已经尝试过您在单击搜索按钮后回显字符串并退出的理论。单击搜索按钮后,它不会回显字符串“xxx”。什么都没有输出。更新后的代码只显示了application 中的代码,因此您也可以自己测试:)
【解决方案2】:

您应该将输入标签移动到 &lt;form method="POST"&gt; &lt;/form&gt; 块内。

【讨论】:

  • 我已经更新了代码和链接以匹配您的答案,但点击搜索按钮后仍然没有显示任何详细信息
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-06
  • 2013-01-14
  • 1970-01-01
  • 1970-01-01
  • 2018-06-17
  • 2021-10-23
  • 1970-01-01
相关资源
最近更新 更多