gpt4 book ai didi

javascript - 使用同一页面上的复选框或单选按钮的 AJAX 过滤 php MySQL 结果

转载 作者:行者123 更新时间:2023-11-29 02:53:09 26 4
gpt4 key购买 nike

我在主页上有一个搜索框。当用户在 home.php 上输入一些值时,该页面将转到 select.php。在选择页面上,我有带复选框、单选按钮和价格范围过滤器的过滤器。

我在单击单选按钮时尝试了一些 jquery,但它的值即将到来并且 sql 查询给出错误。我想根据单选按钮、复选框和价格范围的选择来过滤掉我的结果。所以请给我任何建议。

我已为此尝试了以下代码,

$("#localityid2").click(function () {   


var search_keyword = $("#localityid2").val();
$.ajax({
type: "POST",
url: "select.php",
data: search_keyword ,
success: function () {
window.location.href = "select.php?locality="+search_keyword;

}
});

return false;
});
<table class="sbox">
<tr>
<td>
<div class="radiobtn">
<input type="radio" name="location" class="locality" id="localityid1" value="Aundh" style="float: none;">
</div>
<div class="text">Aundh</div>
</td>
</tr>
<tr>
<td>
<div class="radiobtn">
<input type="radio" name="location" class="locality" id="localityid2" value="Baner" style="float: none;"> </div>
<div class="text">Baner</div>
</td>
</tr>
<tr>
<td>
<div class="radiobtn">
<input type="radio" name="location" class="locality" id="localityid3" value="Ravet" style="float: none;">
</div>
<div class="text">Ravet </div>
</td>
</tr>
<tr>
<td>
<div class="radiobtn">
<input type="radio" name="location" class="locality" id="localityid4" value="Wakad" style="float: none;">
</div>
<div class="text">Wakad</div>
</td>
</tr>
</table>

<h3 style="margin-top: 19px;">Price Range</h3>
<div class="slide-result">
<div id="price-range"></div>
<div class="slide-result">
<input disabled class="amount1" type="text" id="pr1" value="1000" />
<input disabled class="amount2" type="text" id="pr2" value="600000" />
</div>
<div class="clear"></div>
</div>
<h3>AC/Non AC</h3>

<table class="sbox">
<tr>
<td>
<div class="radiobtn">
<input type="checkbox" name="actype[]" class="checkboxclass" value="&actype=1" style="float: none;" />
</div>
<div class="text">AC</div>
</td>
</tr>
<tr>
<td>
<div class="radiobtn">
<input type="checkbox" value="&actype=0" name="actype[]" class="checkboxclass" style="float: none;" />
</div>
<div class="text">Non Ac</div>
</td>
</tr>
</table>




include("db.php");

$city = $_POST['city'];

list($localitys, $citys) = explode(' - ', $city, 2);

$_SESSION['city'] = $citys;

$_SESSION['localitys'] = $localitys;

$_SESSION['event'] = $_POST['events'];

if(isset($_GET['locality']))
{
$sql= mysql_query("SELECT * FROM hall_search_data_1 WHERE city_name='".$_SESSION['city']."' AND hall_evnt_type LIKE '%".$_SESSION['event']."%' AND locality = '".$_GET['locality']."' ")or die(mysql_error());
}
else
{
$sql= mysql_query("SELECT * FROM hall_search_data_1 WHERE city_name='".$_SESSION['city']."' AND hall_evnt_type LIKE '%".$_SESSION['event']."%' ")or die(mysql_error());
}



while($row=mysql_fetch_row($sql))
{
///here my content will print
}

这里是我的 select.php 页面的一些屏幕截图 enter image description here

当我选择任何单选按钮然后给出这样的错误 enter image description here

最佳答案

根据评论,我可以建议对您的代码进行以下修复。

<?php

include("db.php");
$city = '';

if(isset($_POST['city']))
{
$city = $_POST['city'];
list($localitys, $citys) = explode(' - ', $city, 2);
$_SESSION['city'] = $citys;
}

if(isset($_GET['localitys']))
{
$_SESSION['localitys'] = $localitys;
}

if(isset($_POST['events']))
{
$_SESSION['event'] = $_POST['events'];
}
$sql = "";
if(isset($_GET['locality']))
{
$sql .= "SELECT * FROM hall_search_data_1 WHERE 1 = 1 ";

if(isset($_SESSION['city']) && !empty($_SESSION['city']))
$sql .= " AND city_name='".$_SESSION['city']."' ";

if(isset($_SESSION['event']) && !empty($_SESSION['event']))
$sql .= " AND hall_evnt_type LIKE '%".$_SESSION['event']."%' ";

if(isset($_GET['locality']) && !empty($_GET['locality']))
$sql .= " AND locality = '".$_GET['locality']."' ";

mysql_query($sql) or die(mysql_error());
}
else
{
$sql .= "SELECT * FROM hall_search_data_1 WHERE 1 = 1 ";

if(isset($_SESSION['city']) && !empty($_SESSION['city']))
$sql .= " AND city_name='".$_SESSION['city']."' ";

if(isset($_SESSION['event']) && !empty($_SESSION['event']))
$sql .= " AND hall_evnt_type LIKE '%".$_SESSION['event']."%' ";

mysql_query($sql) or die(mysql_error());
}

?>

另外 尝试打印$_POST$_SESSION 数组,这样您就可以知道是否所有参数都正确传递/传递,并且所有 session 设置正确。

关于javascript - 使用同一页面上的复选框或单选按钮的 AJAX 过滤 php MySQL 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33493048/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com