点击弹出窗口中的按钮搜索结果
Search result on click of button in popup
我想在点击按钮时显示搜索结果,但我的代码在没有点击按钮的情况下给了我搜索结果。
我想它给我的是查询结果,而不是搜索结果。
当我在页面上显示结果时,这个代码运行良好,但根据我的要求,我想在弹出窗口上显示搜索结果。
我使用了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"> '.$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"> '.$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>
相关文章:
- AngularJS/HTML/Bootstrap元素用于动态搜索结果
- 如何使用提交按钮搜索表中的记录
- 在web应用程序中的新搜索中重新加载搜索结果(不带jQuery)
- 检查搜索结果是否存在多次如果是,则在Javascript中只显示一个结果
- 显示可链接的搜索结果+对齐方式
- 谷歌位置服务附近搜索结果基于正确的地图中心的位置
- 为自定义网站创建JavaScript搜索框,创建显示搜索结果的弹出窗口
- 主干,如何记住搜索结果
- 为什么不'我的扩展程序不会出现在Chrome网上商店的搜索结果中
- 如何从谷歌自定义搜索下载搜索结果
- (临时)在Web应用程序中存储JSON搜索结果
- Angular JS根据搜索结果和点击事件更新DOM元素
- 停止 jQuery 自动完成以过滤/搜索结果并填充整个源数组数据
- 使用 jQuery UI 折叠面板显示 couchDB 数据库搜索结果时出现问题
- 清除网格中的存储和加载搜索结果
- 引导 3 - 文本输入下的下拉搜索结果
- GoogleMapsForRails-只有在搜索结果发生变化时才通过ajax更新标记
- 需要点击两次按钮才能获得搜索结果
- 点击弹出窗口中的按钮搜索结果
- 选择选项背面丢失按钮&搜索结果恢复为默认选项