Refining Search Results

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

tdp
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Oct 03, 2012 3:44 am

Refining Search Results

Postby tdp » Wed Oct 03, 2012 3:46 am

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

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 (www.javascriptkit.com)
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.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Refining Search Results

Postby seandisanti » Wed Oct 03, 2012 8:21 am

AJAX

tdp
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Oct 03, 2012 3:44 am

Re: Refining Search Results

Postby tdp » Wed Oct 03, 2012 8:44 am

I know..I just have no clue on how to implement AJAX on this...I've been trying all morning..lol

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Refining Search Results

Postby seandisanti » Wed Oct 03, 2012 8:59 am

I'm no expert on ajax myself, but i believe the way that you'd do it is to have a general query generate a big list in the background, and convert the output to xml. then use jquery or regular javascript to chop up and display the data based on form element manipulation.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 3 guests