javascript - 单击弹出窗口中的按钮搜索结果

标签 javascript php jquery html

我想在单击按钮时显示搜索结果,但我的代码在不单击按钮的情况下为我提供搜索结果。

我认为它给我的是查询结果而不是搜索结果。

当我在页面上显示结果时,此代码工作正常,但根据我的要求,我想在弹出窗口上显示搜索结果。

我使用了 jquery 弹出窗口。

<body><form action="#" method="POST"><body><form action="#" method="POST"><div data-role="page">

<div data-role="main" class="ui-content" >

<a href="#a" data-rel="popup" class="ui-btn" onclick="result()" data-transition="slidefade">Smart Search</a>

</div>

 <div data-role="popup" id="a" class="col-sm-6 ui-content">
 <div class="input-group col-sm-8">      
                                  <input type="text" name="query" class="form-control" placeholder="Search Products to Buy..."  "  />

                                                  <span class="input-group-btn">
                                                                            <button name ="search_btn" id ="search class="btn btn-warning" type="submit" value="Search" style="background-color:orange;">Search</button>
                                                  </span>

    </div><div class="input-group col-sm-8 " ><table class="table table-hover">
                   <thead >
                         <tr bgcolor="#1E90FF">
                                <th>Products</th>
                                <th>Details</th>
                                <th>Retailers</th>
                                <th>Price</th>
                                <th>Buy</th>
                       </tr>
                    </thead>
                </div><?php
 error_reporting(0);
 mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
 mysql_select_db("wordpress") or die(mysql_error());
     ?><?php $query = $_POST['query'];  $query = htmlspecialchars($query); 
$query = mysql_real_escape_string($query);
$raw_results=mysql_query("select feed_product_image,feed_product_name,price,deeplink,image from wp_pc_products_merchants e,wp_pc_products w where e.slug=w.id_merchant and feed_product_name LIKE '%".$query."%'") or die(mysql_error());
     if(mysql_num_rows($raw_results) > 0)
    {
    while($results = mysql_fetch_array($raw_results))
        { ?><div class="input-group col-sm-8" style="text-align:center;margin-top:10px;"><tbody>

                      <tr>
                         <td><img src = "<?php  echo $results['feed_product_image'];  ?>"  style="object-fit:contain;height:70px;width:100px;" /></td>
                         <td><?php  echo "<p>".$results['feed_product_name']. "</p>" ; ?></td>
                         <td><img src = "<?php  echo $results['image'];  ?>"  style="background-size:contain;height:40px;width:120px;"  /></td>
                         <td><?php echo '<i class="fa fa-inr">&nbsp;'.$results['price']. '</i>'.".00" ;   ?></td>
                         <td><a href="<?php  echo $results['deeplink'];  ?>" style="background-color:#ff8c21;" class="btn btn-warning btn-md">Buy now</a></td>
                     </tr>
    </tbody>
        </div>  


           <?php 

      }      
    }
    else
    { // if there is no matching rows do following
        echo "No results";
    }




?>

    </div>
    </form>
    </div>

最佳答案

这将在模式弹出窗口中为您提供搜索结果。我对你的代码做了一些更改。如果没有搜索结果,您也可以弹出。

    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

</head>
<body>
      <div data-role="page">

<div data-role="main" class="ui-content" >

<a href="#a" data-rel="popup" class="ui-btn" onclick="result()" data-transition="slidefade">Smart Search</a>

</div>

 <div data-role="popup" id="a" class="col-sm-6 ui-content">
 <div class="input-group col-sm-8">   
     <form  method="POST">
        <input type="text" name="query" class="form-control" placeholder="Search Products to Buy..."  "  />

        <span class="input-group-btn">
                                  <button name ="search_btn" id ="search" class="btn btn-warning" type="submit" value="Search" style="background-color:orange;">Search</button>
        </span>
     </form>

    </div>

    <?php
        if(isset($_POST['query']) && $_POST['query']!="" ) {
        error_reporting(0);
        mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
        mysql_select_db("wordpress") or die(mysql_error());
        $query = $_POST['query'];  $query = htmlspecialchars($query); 
        $query = mysql_real_escape_string($query);
        $raw_results=mysql_query("select feed_product_image,feed_product_name,price,deeplink,image from wp_pc_products_merchants e,wp_pc_products w where e.slug=w.id_merchant and feed_product_name LIKE '%".$query."%'") or die(mysql_error());


        if(mysql_num_rows($raw_results) > 0)
        {
    ?>
    <div class="input-group col-sm-8  modal-box"  id="popup" title="Search Results" style="text-align:center;margin-top:10px;">
      <table class="table table-hover">
         <thead >
               <tr bgcolor="#1E90FF">
                      <th>Products</th>
                      <th>Details</th>
                      <th>Retailers</th>
                      <th>Price</th>
                      <th>Buy</th>
             </tr>
          </thead>
          <tbody>
    <?php 
        while($results = mysql_fetch_array($raw_results))
        { ?>

                      <tr>
                         <td><img src = "<?php  echo $results['feed_product_image'];  ?>"  style="object-fit:contain;height:70px;width:100px;" /></td>
                         <td><?php  echo "<p>".$results['feed_product_name']. "</p>" ; ?></td>
                         <td><img src = "<?php  echo $results['image'];  ?>"  style="background-size:contain;height:40px;width:120px;"  /></td>
                         <td><?php echo '<i class="fa fa-inr">&nbsp;'.$results['price']. '</i>'.".00" ;   ?></td>
                         <td><a href="<?php  echo $results['deeplink'];  ?>" style="background-color:#ff8c21;" class="btn btn-warning btn-md">Buy now</a></td>
                     </tr>



           <?php 

      }   
      ?>
                     </tbody>
                </table>

        </div>  

      <?php 
        }
        else
        { // if there is no matching rows do following
            echo "No results";
        }

       }
    ?>

    </div>
    </form>
    </div>
        <script>
          $(function() {
            $( "#popup" ).dialog();
          });
          </script>

关于javascript - 单击弹出窗口中的按钮搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33538039/

相关文章:

javascript - 同时动态创建多个输入

jquery - MooTools 导致 jQuery Web 应用程序外部崩溃

JQuery UI Accordion,如何使用另一个函数将按钮/链接放置到标题

javascript - Lodash:是否可以将 map 与异步功能一起使用?

javascript - 是否有任何 Javascript 功能可以让您检查元素是否已关闭?

javascript - Eslint,如何在Javascript中接受const和箭头函数?

php - 将数组转换为 WHERE IN mysql 子句的格式

javascript - 使用 javascript/jquery 读取输入字段的值并自动分配 var 类型

php - MySQL跨表删除

php - Controller 与模型——需要解释