[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.6

Filtering the search results based on the drop down menu select

Asked by PranjalShah in Miscellaneous Web Development, PHP and Databases

Tags: web development, php, mysql

I am creating this question again since the AJAX work did not completely solve my problem. I am trying to filter my search results based on the dropdown selection. In the code below, I am generating two drop down boxes based on the search criteria. I want to filter the results based on that selection. I believe if I can pass the value of the selected value and run the query with that, it should show the filtered results...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
<?php
//error handling
//ini_set('error_reporting',E_ALL);
//ini_set('display_errors',1);
include 'main_new.php';
include_once('../inludes/db.php');
?><!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=utf-8" />
<link rel="stylesheet" type="text/css" media="screen" href="../builder/chassis/css/table.css" />
<script src="js/sorttable.js"></script>
<title>Search</title>
</head>
<body>
<form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
 <input type="text"  onfocus="this.value = (this.value=='Enter your search...')? '' : this.value;" value="Enter your search..." name="q" />
  <input type="submit" name="Submit" value="Search" />
</form> 
<?php
  // Get the search variable from URL
 
  $var = (!empty($_GET['q'])) ?  mysql_real_escape_string(trim($_GET['q'])) : '';
 
// rows to return
$limit=25; 
 
// check for an empty string and display a message.
if (empty($var))
  {
  echo "<p></p>";
  exit;
  }
 
// Build SQL Query  
$query = "SELECT ID,name,description,vendor,IFNULL(price,'N/A')price,IFNULL(cost,'N/A')cost,IFNULL(category,'N/A')category,IFNULL(subcategory,'N/A')subcategory FROM prices WHERE name LIKE '%$var%' OR description LIKE '%$var%' OR vendor LIKE '%$var%' OR category LIKE '%$var%' OR subcategory LIKE '%$var%'";
//$query = "SELECT * FROM prices WHERE name LIKE '%$var%' OR description LIKE '%$var%' OR vendor LIKE '%$var%' OR category LIKE '%$var%' OR subcategory LIKE '%$var%'"; // EDIT HERE and specify your table and field names for the SQL query
 
 
  $drop1="select id, IFNULL(category,'N/A')category from prices where name LIKE '%$var%' OR description LIKE '%$var%' OR vendor LIKE '%$var%' OR category LIKE '%$var%' OR subcategory LIKE '%$var%' group by category order by id asc";
   
   $drop2="select id, IFNULL(subcategory,'N/A')subcategory from prices where name LIKE '%$var%' OR description LIKE '%$var%' OR vendor LIKE '%$var%' OR category LIKE '%$var%' OR subcategory LIKE '%$var%' group by subcategory order by id asc";
 
 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
 
// If we have no results, offer a google search as an alternative
 
if ($numrows == 0)
  {
  echo "<h4>Results</h4>";
  echo "<p>Sorry, your search: &quot;" . $var . "&quot; returned zero results</p>";
  }
 
// next determine if s has been passed to script, if not use 0
 $s = (!empty($_GET['s'])) ?  intval($_GET['s']) : 0;
 
// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");
 
// display what the person searched for
echo "<p>Your search results for <strong> &quot;" . $var . "&quot;</strong> are as below..</p>";
 
// begin to show results set
//echo "<h4>Results</h4>";
$count = 1 + $s ; 
$currPage = (($s/$limit) + 1); 

echo "<select>";
  //echo "<option>Filter by Category</option>";
  $res=mysql_query($drop1);
  echo "<option>Filter by Category</option>";
  while(list($id,$category)=mysql_fetch_row($res))
  {
	  
	  echo "<option value=\"".$id."\">".$category."</option>";
  }
  
echo "</select>&nbsp;&nbsp;OR&nbsp;&nbsp;";
echo "<select>"; 
echo "<option>Filter by Subcategory</option>";
  $res2=mysql_query($drop2);
  while(list($id,$subcategory)=mysql_fetch_row($res2))
  {
	  echo "<option value=\"".$id."\">".$subcategory."</option>";
  }
  echo "</select>";
  
 
//break before paging
  echo "<br />";
 
  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print " <a href=\"$_SERVER[PHP_SELF]?s=$prevs&q=$var\">&lt;&lt; 
  Prev $limit</a>&nbsp ";
  }
 
// calculate number of pages needing links
  $pages=intval($numrows/$limit);
 
// $pages now contains int of pages needed unless there is a remainder from division
 
  if ($numrows%$limit) {
  // has remainder so add one page
  $pages++;
  }
 
// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
 
  // not last page so give NEXT link
  $news=$s+$limit;
 
  echo " <a href=\"$_SERVER[PHP_SELF]?s=$news&q=$var\">Next $limit &gt;&gt;</a>";
  }
  
// now you can display the results returned
  /*while ($row= mysql_fetch_array($result)) {
  $title = $row["name"];
 
  echo "$count.) $title<br>" ;
  $count++ ;
  }
 */
 if(mysql_num_rows($result) )
{
	
  echo "<table width=50% border=1 class=sortable>";
  echo "<tr><th> </th><th>No</th><th>Name</th><th>Description</th><th>Vendor</th><th>List Price</th><th>Street Price</th><th>Category</th><th>Sub Category</th></tr>";
// now you can display the results returned
  while ($row= mysql_fetch_array($result)) {
	if($row['cost']=="N/A") {$dol1="";} else {
	
	$dol1 = "$";  }
	$dol = "$";
  echo "<tr><td><input type='checkbox' name='price[]' value='{$row['ID']}' /></td><td>{$count}</td><td>{$row['name']}</td><td>{$row['description']}</td><td>{$row['vendor']}</td><td>$dol{$row['price']}</td><td>$dol1{$row['cost']}</td><td>{$row['category']}</td><td>{$row['subcategory']}</td></tr>";
  $count++ ;
  }
  echo "</table>";
}
$currPage = (($s/$limit) + 1);
 
//break before paging
  echo "<br />";
 
  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print " <a href=\"$_SERVER[PHP_SELF]?s=$prevs&q=$var\">&lt;&lt; 
  Prev $limit</a>&nbsp ";
  }
 
// calculate number of pages needing links
  $pages=intval($numrows/$limit);
 
// $pages now contains int of pages needed unless there is a remainder from division
 
  if ($numrows%$limit) {
  // has remainder so add one page
  $pages++;
  }
 
// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
 
  // not last page so give NEXT link
  $news=$s+$limit;
 
  echo " <a href=\"$_SERVER[PHP_SELF]?s=$news&q=$var\">Next $limit &gt;&gt;</a>";
  }
 
$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";
  
?></body>
</html>
 
Related Solutions
Keywords: Filtering the search results based on th…
 
Loading Advertisement...
 
[+][-]11/12/09 03:00 PM, ID: 25809861Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Miscellaneous Web Development, PHP and Databases
Tags: web development, php, mysql
Sign Up Now!
Solution Provided By: PranjalShah
Participating Experts: 2
Solution Grade: A
 
[+][-]11/06/09 10:42 AM, ID: 25761791Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/09 12:13 PM, ID: 25798552Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/09 12:23 PM, ID: 25798625Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/09 12:33 PM, ID: 25798719Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/09 04:51 PM, ID: 25810416Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/13/09 06:11 AM, ID: 25813988Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/13/09 06:12 AM, ID: 25813994Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]11/13/09 06:12 AM, ID: 25813997Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625