Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
//This is my jobsearch.html

//I am selecting values from all the dropdowns and populating them to search.php where I will be getting job_title from database.

//What i need is, i should display the number of jobs with respect to "job_count"(Drop Down) 


<html>
<head>
<style>

#job_listings
{

background-color:#00FFFF;
width:500px;
height:100px;
overflow:scroll;

}

</style>
<h4>Job Search</h4>	
	<script type="text/javascript"></script>
	<script src="../js/jquery-1.9.1.js"></script>
	<script src="../js/jquery.tmpl.min.js"></script>
<script>
		jQuery(document).ready(function() 
		{
			jQuery.ajax(
			{
				type: 'GET',
				url: 'sample.php',
				dataType: 'JSON',
				success:function(data)
				{
					for(i=0;i<jQuery(data).length;i++)
					{
						jQuery('#jobcategory').append('<option value = '+ data[i].jobcategory+'>' + data[i].jobcategory + '</option>');
					}
				}
			});
		});
</script>

<script>
		jQuery(document).ready(function() 
		{
			jQuery.ajax(
			{
				type: 'GET',
				url: 'sample.php',
				dataType: 'JSON',
				success:function(data)
				{
					for(i=0;i<jQuery(data).length;i++)
					{
						jQuery('#jobtype').append('<option value = '+ data[i].jobtype+'>' + data[i].jobtype + '</option>');
					}
				}
			});
		});
</script>

<script>
		jQuery(document).ready(function() 
		{
			jQuery.ajax(
			{
				type: 'GET',
				url: 'sample.php',
				dataType: 'JSON',
				success:function(data)
				{
					for(i=0;i<jQuery(data).length;i++)
					{
						jQuery('#company').append('<option value = '+ data[i].company+'>' + data[i].company + '</option>');
					}
				}
			});
		});
</script>

 
<script>
jQuery(document).ready(function() 
		{
			jQuery('#submit').click(function()
			{

				var jobDetails =[];

				var obj={};


				obj.jobcategory=jQuery('#jobcategory').val();

				obj.jobtype=jQuery('#jobtype').val();

				obj.company=jQuery('#company').val();

				obj.startdate=jQuery('#startdate').val();

				obj.enddate=jQuery('#enddate').val();

				obj.jobcount=jQuery('#jobcount').val();

				jobDetails.push(obj);

			var jsonString =JSON.stringify(jobDetails);


		
				jQuery.ajax(
				{
					type: 'GET',
					url: 'search.php',
					data: { 'jobDetailsData': jsonString },
					success:function(data)
					{

						{
						jQuery('#job_listings').append(data);
						}
						
					}
					
				});
			});
		});

	</script>

</head>
<body>
	<form id="search" name="jobSearch">
		<div>
			Job Categories:<select id="jobcategory" value="jobcategory">
			<option>Select Job Category</option>
			</select><br><br>


			Job Type:<select id="jobtype" value="jobtype">
			<option>Select Job Type</option>
			</select><br><br>

			Company:<select id="company" value="company">
			<option>Select Company</option>
			</select><br><br>

			Start Date:<input type="date" id="startdate" value="startdate"><br><br>

			End Date:<input type="date" id="enddate" value="enddate"><br><br>

			No. Of Jobs:<select id="jobcount" value="jobcount">
			<option>Select</option>
			<option>5</option>
			<option>10</option>
			<option>15</option>
			<option>20</option>
			</select><br><br>

			<input type="button" id="submit" value="Submit"/>

			</div>

<div id="job_listings" style="" class=jobs_list>

</div>
</form>
</body>
</html>




//This is my search.php

<?php
mysql_connect("localhost","root","");

mysql_select_db("plugins");

$jobDetailsData = json_decode($_GET['jobDetailsData']);

foreach($jobDetailsData as $jobDetailsData)
{
$jobcategory = mysql_real_escape_string($jobDetailsData->jobcategory);
$jobtype = mysql_real_escape_string($jobDetailsData->jobtype);
$company = mysql_real_escape_string($jobDetailsData->company);
$startdate = mysql_real_escape_string($jobDetailsData->startdate);
$enddate = mysql_real_escape_string($jobDetailsData->enddate);
$jobcount = mysql_real_escape_string($jobDetailsData->jobcount);


$result=mysql_query("select job_title from job_listings where (job_category='$jobcategory' OR job_type='$jobtype' OR company_name='$company') AND (start_date='$startdate' AND end_date='$enddate')");



}
//echo $result;
$data=array();
if($result)
{


	while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 

		{ 

		$row_array['job_title'] = $row['job_title'];

		array_push($data,$row_array);

		}


}
echo json_encode($data);



mysql_close();

?>


//please help me on this
Posted
Updated 23-Mar-14 17:52pm
v3
Comments
Janardhanam Julapalli 20-Mar-14 5:06am    
Anyone help me out on this
CHill60 23-Mar-14 13:15pm    
Do yourself a favour ... use the Improve question link next to your question. Highlight all of the code segment and hit Ctrl-C. Now hit Del. Now use Ctrl-V ... a pop-up menu will appear to the right, select the "Code Block" radio button and hit ok, then submit your question again. It will go back into the queue, and should be easier for people to read. While you are doing that you might want to remove any code that isn't relevant to your question

1 solution

your code is hard to understand... use proper styling

but what i understood is you want to limit the no of results frm a sql query to a no from dropdown list... here it is.. improve your query to

select job_title from job_listings where (job_category='$jobcategory' OR job_type='$jobtype' OR company_name='$company') AND (start_date='$startdate' AND end_date='$enddate') limit yourNumber(dropdown list value)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900