Jump to content

[SOLVED] Help with Multiple Combo box filtering script


ricscott

Recommended Posts

Hi everyone,

I've been trying to get to grips with this script for a while now and, TBH I'm going bald now over it...

It's probably something really basic that's going wrong or, I've totally screwed the script..

 

I've got 4 <option> boxes with choices in...

eg:

<select name="items" class="seach-box" id="items">
        <option value="#">Please Choose</option>
	<option value="0">Any</option>
        <option value="1">Item1</option>
        <option value="2">Item2</option>
      </select>

etc...Then the submit...

<input name="search" type="submit" class="search-button" id="search" value="Find" />

etc..

 

Then on the php side...

 

$type=$_GET[type];
$price=$_GET[price];

// link to data
$link_id = mysql_connect("local","user","pass");
if (mysql_select_db("db", $link_id));
else die ("connection failed.") ;

// Determine where in the database to start returning results.
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}

$flag = 0;
$query_search="";

if($type=="Any")
if($type !=="0")// if search is NOT for all a bit more needs to be added
{
if($type=="1")
{
$prop_type="item1";
}
if($type=="2")
{
$prop_type="item2";
}
if($type=="3")
{
$prop_type="item3";
}
if($type=="4")
{
$prop_type="item4";
}
// And so on

$query_search.= " WHERE type = '$prop_type' ";

}

if($price !=="0")
{
if($price=="1")
{
$range=" < 100000 ";
}
if($price=="2")
{
$range=" BETWEEN 100000 and 200000";
}
if($price=="3")
{
$range=" BETWEEN 200000 and 400000";
}
if($price=="4")
{
$range=" 400000 >";
}
//And So On
{
$query_search.= " AND price = '$range' ";
}else{
$query_search.= " WHERE price = '$range' ";
}
}

$sql="SELECT ID, and everything else etc FROM tbl $query_search";
$result = @mysql_query ($sql);

 

Pls help...this is now becomming urgent...I'm using MySQL 5.0.27 and PHP 5.2.0

is there another way??

first fault

<?php
// your first two lines
$type=$_GET[type];
$price=$_GET[price];

//should read
$type=$_GET['type'];
$price=$_GET['price'];

// we will assume that they are being set properly

//second error change this line
$result = @mysql_query ($sql); // the @ sysmbol stops errors being shown

//for this
$result = mysql_query($sql) or die('Invalid query: ' . mysql_error());
?>

and find out if there is a fault with the building of your query

Thanks for the reply..

I tried what you suggested and just got a blank screen if I choose an option, however, before, I failed to mention, if I just choose, 'Any' from both boxes I get a result...all the items from the db, but now, just a blank screen...

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.