Filter on search results

js code

$(document).ready(function() {
    function showValues() {
		
		$("#wrapper").css("opacity","0.4");
		$( "#loading-image" ).show(0);	
		var mainarray = new Array();
		
		var subcategoriesarray = new Array();		
		$('input[name="subcategories"]:checked').each(function(){			
			subcategoriesarray.push($(this).val());		
			
		});
		
		var subcategories_checklist = "&subcategories="+subcategoriesarray;
				
		var job_typearray = new Array();		
		$('input[name="job_type"]:checked').each(function(){			
			job_typearray.push($(this).val());	
			
		});
		
		var job_type_checklist = "&job_type="+job_typearray;
		
		
		var budgetarray = new Array();		
		$('input[name="budget"]:checked').each(function(){			
			budgetarray.push($(this).val());
					
		});
		
		var budget_checklist = "&budget="+budgetarray;
		
		
		var experiencearray = new Array();		
		$('input[name="experience"]:checked').each(function(){			
			experiencearray.push($(this).val());
					
		});
		
		var experience_checklist = "&experience="+experiencearray;
		
		var job_durationarray = new Array();		
		$('input[name="job_duration"]:checked').each(function(){			
			job_durationarray.push($(this).val());
					
		});
		
		var job_duration_checklist = "&job_duration="+job_durationarray;
		var category = $("#category_selectbox").val();
		if(category.length > 0){
		var categoryname = "&category="+category;
		var main_string = subcategories_checklist+job_type_checklist+budget_checklist+experience_checklist+job_duration_checklist+categoryname;
		}
		else {
		var main_string = subcategories_checklist+job_type_checklist+budget_checklist+experience_checklist+job_duration_checklist;
		}
		main_string = main_string.substring(1, main_string.length)
		//alert(main_string);
		
		
		$.ajax({
			type: "POST",
			url: "ajax/filter_jobs.php",
			data: main_string, 
			cache: false,
			success: function(html){
				//alert(html);
				$("#place_content_here").html(html);		
				$("#wrapper").css("opacity","1");
				$( "#loading-image" ).hide(0);
				
				
				
			}
			});
		
		
	}
	
	$("input[type='checkbox']").on( "click", showValues );
    $("select").on( "change", showValues );

PHP filter queries




<?php
//error_reporting(E_all);
include("../includes/database.php");
$subcategory = $_REQUEST['subcategories'];
$workload = $_REQUEST['job_type'];
$budget = $_REQUEST['budget'];
$experience = $_REQUEST['experience'];
$job_duration = $_REQUEST['job_duration'];
$category = $_REQUEST['category'];

$query = "select * from job where";
$where = array();
if(!empty($category)){
$where[] = " category = $category";
}
if(!empty($subcategory)){
$where[] = " subcategory IN($subcategory)";
}
if(!empty($workload)){
$workload = explode(",",$workload);
$workload = "'".implode("','", $workload)."'";
$where[] = " workload IN($workload)";
}
if(!empty($budget)){
$budget = explode(",",$budget);
$budget = "'".implode("','", $budget)."'";
$where[] = " budget IN($budget)";
}
if(!empty($experience)){
$experience = explode(",",$experience);
$experience = "'".implode("','", $experience)."'";
$where[] = " desired_experience IN($experience)";
}
if(!empty($job_duration)){
$job_duration = explode(",",$job_duration);
$job_duration = "'".implode("','", $job_duration)."'";
$where[] = " duration IN($job_duration)";
}
    

$where = implode(" or ",$where);
$query .= $where;
//echo $query;
$jobs = mysql_query($query);
function time_ago($date)

											{

											if(empty($date)) {

											return "No date provided";

											}

											$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");

											$lengths = array("60","60","24","7","4.35","12","10");

											$now = time();

											$unix_date = strtotime($date);

											// check validity of date

											if(empty($unix_date)) {

											return "Bad date";

											}

											// is it future date or past date

											if($now > $unix_date) {

											$difference = $now - $unix_date;

											$tense = "ago";

											} else {

											$difference = $unix_date - $now;
											$tense = "from now";}

											for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {

											$difference /= $lengths[$j];

											}

											$difference = round($difference);

											if($difference != 1) {

											$periods[$j].= "s";

											}

											return "$difference $periods[$j] {$tense}";

											}
?>
						<div class="search_btm_text">
                    	
						<?php
						   
						   if(mysql_num_rows($jobs) > 0){
	                       while($job = mysql_fetch_array($jobs))
			                { //echo "<pre>";print_r($job);
                              ?>
                        <div class="work_div">
                        	<h4><a href="job_detail.php?number=<?php echo base64_encode($job['id']);?>"><?php echo $job['title'];?></a></h4>
                            <div class="supported_info">
                            	<p><strong class="fixedprice"><?php echo $job['workload'];?>:<?php echo ucfirst($job['desired_experience']);?> level </strong>Budget :<strong><?php echo $job['budget'];?></strong> - Posted <?php echo time_ago($job['date']);?></p>
                               
                            </div><!--supported_info-->
                            <div class="cDescription"><p><?php echo $job['description'];?>....<a href="job_details.php?job=<?php echo $job['id'];?>">more</a></p></div>
                            <div class="supported_info">
                            	<p><strong class="ipaid">Client: </strong><img src="assets/images/star4.png" alt=""><strong>Working Hours:<?php echo $job['duration'];?> </strong> 
								<?php 
										if(!empty($job['qualification'])){
										$quali = mysql_query("select * from skills where id IN(".$job['qualification'].")");
											$array = array(); 
											while($skil = mysql_fetch_array($quali)){
												$array = $skil['skill'];
											}
											echo implode(",",$array);
										}
										
										?>
								</p>
                                
                            </div>
                        </div><!--work_div-->
						
						<?php } } else { ?>
						 <div class="work_div">
						 <h4>No matching results were found !</h4>
						 </div>
						<?php } ?>
                       <?php //echo $pagination;?>
                      
                    </div><!--search_btm_text-->

	
	
	
});	


Html code

<div class="my_categories">
                    	<h5>Choose Category</h5>
                        <select class="categories_list" id="category_selectbox" name="category" onchange="get_subcategory($(this).val());">
						<?php $cats  = mysql_query("select * from categories"); 
						 while($c = mysql_fetch_array($cats)){
						?>
                        	<option value="<?php echo $c['id'];?>"><?php echo $c['name'];?></option>
                           
							<?php } ?>
                        </select>
                    </div><!--my_categories-->
					<div class="my_categories">
                    	<h5>Sub Categories</h5>
                        <ul class="categories_list" id="subcategory_checkbox12">
						<?php $subcats = mysql_query("select * from subcategories where category_id = 7");
						while($subcat = mysql_fetch_array($subcats)){
						?>
						<li><input type="checkbox" class="subcat_checkbox" name="subcategories" value="<?php echo $subcat['id'];?>"/><?php echo $subcat['name'];?></li>
						<?php } ?>
                        </ul>
                    </div><!--my_categories-->
					<div class="my_categories">
                    	<h5>Job type</h5>
                        <ul class="categories_list">
						
                        	<li><input type="checkbox" name="job_type" class="job_type" value="Part Time"/>Part Time</li>
                           <li><input type="checkbox" name="job_type" class="job_type" value="Full Time"/>Full Time</li>
						
                        </ul>
                    </div><!--my_categories-->
					<div class="my_categories">
                    	<h5>Budget</h5>
                        <ul class="categories_list">
						
                        	<li><input type="checkbox" name="budget" class="budgets" value="Less than 100$"/>Less than 100$</li>
                           <li><input type="checkbox" name="budget" class="budgets" value="Between $100 & $500"/>Between $100 & $500</li>
						   <li><input type="checkbox" name="budget" class="budgets" value="Between $500 & $1000"/>Between $500 & $1000</li>
                           <li><input type="checkbox" name="budget" class="budgets" value="Greater then $1000"/>Greater then $1000</li>
						   <li><input type="checkbox" name="budget" class="budgets" value="Not sure.."/>Not sure..</li>
                        </ul>
                    </div><!--my_categories-->
					<div class="my_categories">
                    	<h5>Experience</h5>
                        <ul class="categories_list">
						
                        	<li><input type="checkbox" name="experience" class="experience" value="entry"/>Entry Level</li>
                           <li><input type="checkbox" name="experience" class="experience" value="intermediate"/>Intermediate Level</li>
						   <li><input type="checkbox" name="experience" class="experience" value="expert"/>Expert Level</li>
						
                        </ul>
                    </div><!--my_categories-->
					<div class="my_categories">
                    	<h5>Job Duration</h5>
                        <ul class="categories_list">
						
                        	<li><input type="checkbox" name="job_duration" class="job_duration" value="Less then 1 week"/>Less than 1 Week</li>
                           <li><input type="checkbox" name="job_duration" class="job_duration" value="Less then 1 months"/>Less than 1 Month</li>
						   <li><input type="checkbox" name="job_duration" class="job_duration" value="1 to 3 months"/>1 to 3 Months</li>
							<li><input type="checkbox" name="job_duration" class="job_duration" value="3 to 6 months"/>3 to 6 Months</li>
							<li><input type="checkbox" name="job_duration" class="job_duration" value="More then 6 months"/>More than 6 Months</li>
                        </ul>
                    </div><!--my_categories-->
                
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s