/    Sign up×
Community /Pin to ProfileBookmark

Refining Search Results…

I would like to refine the results of mysql query using dropdown boxes… live site is here:
[url]http://www.halfwayenterprises.com/search/tyrell.php[/url]

and here is the coding:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>

<body>

<form name=”doublecombo” action=”” method=”POST”>

<label for=”status”>Status:</label>

<label for=”current”>
<input class=”radio_style” id=”current” checked=”checked” name=”status” type=”radio” value=”current”>
Current
</label>

<label for=”obsolete”>
<input class=”radio_style” id=”obsolete” name=”status” type=”radio” value=”obsolete”>
Obsolete
</label>

<label for=”both”>
<input class=”radio_style” id=”both” name=”status” type=”radio” value=”both”>
ALL
</label>

<br /><br />

<select name=”category” size=”1″ onChange=”redirect(this.options.selectedIndex)”>
<option value=”null”>Category</option>
<option value=”asset management”>Asset Management</option>
<option value=”budget”>Budget/Finance</option>
<option value=”central office”>Central Office</option>
<option value=”disposal”>Disposal</option>
</select>

<select name=”subcategory”>
<option value=”null”>Sub-Category</option>
<option value=”Portfolio”>Portfolio</option>
<option value=”Pricing”>Pricing</option>
<option value=”Valuation”>Valuation</option>

<option value=”Disposal”>Disposal</option>

</select>
<input name=”submitted” type=”submit” value=”GO”>

<br />

Seach for: <input type=”text” name=”find” /> in
<Select NAME=”field”>
<Option id=”title” VALUE=”title”>Title</option>
<Option id=”poc” VALUE=”poc”>POC</option>
<Option id=”purpose” VALUE=”purpose”>Purpose</option>

</Select>

<input type=”hidden” name=”searching” value=”yes” />

<input name=”submitted” type=”submit” value=”GO”>

</form>

<select name=”filter1″>
<option value=”az”>Sort by A-Z</option>
<option value=”date”>Sort by Date</option>
</select>

<select name=”filter2″>
<option value=”office”>Sort by Office</option>
<option value=”p”>P</option>
<option value=”pt”>PT</option>
<option value=”pf”>PF</option>
</select>

<select name=”filter3″>
<option value=”mandatory”>Mandatory</option>
<option value=”nonmandatory”>Non-Mandatory</option>
<option value=”combined”>Combined</option>
</select>

</form>

</p>

<script>
<!–

/*
Double Combo Script Credit
By JavaScript Kit ([url]www.javascriptkit.com[/url])
Over 200+ free JavaScripts here!
*
/

var groups=document.doublecombo.category.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option(“Sub Category”)

group[1][0]=new Option(“Portfolio”)
group[1][1]=new Option(“Pricing”)
group[1][2]=new Option(“Valuation”)

group[3][0]=new Option(“Central Office”)
group[4][0]=new Option(“Disposal”)

var temp=document.doublecombo.subcategory

function redirect(x){
for (m=temp.options.length-1;m>0;m–)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}
//–>
</script>

<?

mysql_connect(“localhost”, “name”, “pasword”) or die(mysql_error());
mysql_select_db(“db”) or die(mysql_error());

if(isset($_POST[“submitted”])){

$status = $_POST[‘status’];

$category = $_POST[‘category’];
$subcategory = $_POST[‘subcategory’];

echo ‘<div class=”status_div”>’;

if($status==’current’)

{
echo “<h2>Results</h2><p>”;

$res = mysql_query(“SELECT * FROM material WHERE status=’$status’ AND category=’$category’ AND subcategory=’$subcategory’ ORDER BY `documentid` ASC”);

while ($row = mysql_fetch_assoc($res)) {

echo ‘<div class=”current”>’;

echo $row [‘documentid’].’ – ‘.$row[‘category’].’ – ‘.$row[‘title’].’ – ‘.$row[‘status’];

echo ‘</div>’;

echo ‘<br>’;

}

} if ($status==’obsolete’)

{
echo “<h2>Results</h2><p>”;
$res = mysql_query(“SELECT * FROM material WHERE status=’$status’ AND category=’$category’ ORDER BY `documentid` ASC “);

while ($row = mysql_fetch_assoc($res)) {

echo $row [‘documentid’].’ – ‘.$row[‘category’].’ – ‘.$row[‘title’].’ – ‘.$row[‘status’];

echo ‘<br>’;

}

} if ($status==’both’)

{

echo “<h2>Results</h2><p>”;
$res = mysql_query(“SELECT * FROM material WHERE status1=’both’ AND category=’$category’ ORDER BY `documentid` ASC”);

while ($row = mysql_fetch_assoc($res)) {
echo ‘<div class=””>’;

echo $row [‘documentid’].’ – ‘.$row[‘category’].’ – ‘.$row[‘title’].’ – ‘.$row[‘status’];

echo ‘</div>’;

echo ‘<br>’;

}

}

echo ‘</div>’;

}

$field = @$_POST[‘field’] ;
$find = @$_
POST[‘find’] ;
$searching = @$_POST[‘searching’] ;
$status = $_
POST[‘status’];

//This is only displayed if they have submitted the form
if ($searching ==”yes”)
{
echo “<h2></h2><p>”;

//If they did not enter a search term we give them an error
if ($find == “”)
{

echo “<a href=’tyrell.htm’>Return</a>”;
exit;
}

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified

if($status==’current’){

$data = mysql_query(“SELECT * FROM material WHERE status=’$status’ AND lower($field) LIKE’%$find%’ LIMIT 0,30”);

while ($row = mysql_fetch_assoc($data)) {

echo ‘<div class=”current”>’;

echo $row [‘documentid’].’ – ‘.$row[‘category’].’ – ‘.$row[‘title’].’ – ‘.$row[‘status’];

echo ‘</div>’;

echo ‘<br>’;

}

}

if ($status==’obsolete’){

$data = mysql_query(“SELECT * FROM material WHERE status=’$status’ AND lower($field) LIKE’%$find%’ LIMIT 0,30”);

while ($row = mysql_fetch_assoc($data)) {

echo ‘<div class=”obsolete”>’;

echo $row [‘documentid’].’ – ‘.$row[‘category’].’ – ‘.$row[‘title’].’ – ‘.$row[‘status’];

echo ‘</div>’;

echo ‘<br>’;

}

} if ($status==’both’){

$data = mysql_query(“SELECT * FROM material WHERE status1=’both’ AND lower($field) LIKE’%$find%’ LIMIT 0,30”);

while ($row = mysql_fetch_assoc($data)) {

echo ‘<div class=””>’;

echo $row [‘documentid’].’ – ‘.$row[‘category’].’ – ‘.$row[‘title’].’ – ‘.$row[‘status’];

echo ‘</div>’;

echo ‘<br>’;

}

}

//This counts the number or results – and if there wasn’t any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo “Sorry, but we can not find an entry to match your query<br><br>”;
}

//And we remind them what they searched for
echo “<b>Searched For:</b> ” .$find;
}

?>

<p align=”center”><font face=”arial” size=”-2″>This free script provided by</font><br>
<font face=”arial, helvetica” size=”-2″><a href=”http://javascriptkit.com”>JavaScript
Kit</a></font></p>’
</body>
</html>

I have can’t think of how to use the drop downs without having a submit button

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @tdp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...