2

I have one search box on home page. when user enter the some value on home.php then that page goes to select.php. On select page i have filters with checkboxes, radio button & price range filter.

I have tried some jquery on click of radio button but its value are coming and sql query giving error. I want to filter out my result according to selection of radio button, checkboxes & price range. so please suggset any to me.

i have tried following code for this,

$("#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
}

here some screen shot my select.php page enter image description here

when i select any radio button then giving error like this enter image description here

16
  • Please write down error here. Also you have not started session. So, please check that $_SESSION['city'] might be blank. Commented Nov 3, 2015 at 6:55
  • if you want to redirect to select.php page then why are you using JQuery, passing data and then redirecting to that page? You can minimize the code a lot. Commented Nov 3, 2015 at 6:57
  • @sandeepsure no it contain some value of city Commented Nov 3, 2015 at 6:58
  • @Suyog no i want filter on same page(select.php). Commented Nov 3, 2015 at 6:59
  • "sql query giving error" - what kind of error? Commented Nov 3, 2015 at 7:00

1 Answer 1

1

From the comments, I can suggest following fixes to your code.

<?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());
}

?>

Also try printing $_POST and $_SESSION arrays so that you can come to know whether all parameters are passing/ passing correctly and all the sessions are setting up properly.

Sign up to request clarification or add additional context in comments.

6 Comments

thanks its working fine for radio button. but one problem is that for the checkbox & price range filtering.
what problem in those? You will have to apply similar things to all the filters to work them as expected.
when i select radio button it shows correct value or result but that checkbox will not remain checked.
You will have to modify it to <input type="radio" name="location" class="locality" id="localityid1" value="Aundh" style="float: none;" <?php if(isset($_GET['locality']) && $_GET['locality'] == 'Aundh') echo "selected='selected'"; ?>>
please help me for pricing range.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.