本文介绍了如何显示没有。来自MYSQL的项目,基于从Dropdown中选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//这是我的jobsearch.html
//我从所有下拉列表中选择值并将它们填充到search.php,我将从数据库中获取job_title 。
//我需要的是,我应该显示与job_count相关的工作数量(下拉)
& lt; html& GT;
& lt; head& gt;
& lt; style& gt;
#job_listings
{
background-color:#00FFFF;
宽度:500px;
身高:100px;
溢出:滚动;
}
& lt; / style& gt;
& lt; h4& gt;职位搜索& lt; / h4& gt;
& lt; script type =text / javascript& gt;& lt; / script& gt;
& lt; script src =../ js / jquery-1.9.1.js& gt;& lt; / script& gt;
& lt; script src =../ js / jquery.tmpl.min.js& gt;& lt; / script& gt;
& lt; script& gt;
jQuery(document).ready(function()
{
jQuery.ajax(
{
type:'GET',
url:'sample .php',
dataType:'JSON',
成功:函数(数据)
{
for(i = 0; i& lt; jQuery(data).length; i ++)
{
jQuery('#jobcategory')。append('& lt; option value ='+ data [i] .jobcategory +'& gt;'+ data [i] .jobcategory +'& lt; / option& gt;');
}
}
});
});
& lt; / script& gt;
& lt; script& gt;
jQuery(document).ready(function()
{
jQuery.ajax(
{
type:'GET',
url:'sample .php',
dataType:'JSON',
成功:函数(数据)
{
for(i = 0; i& lt; jQuery(data).length; i ++)
{
jQuery('#jobtype')。append('& lt; option value ='+ data [i] .jobtype +'& gt;'+ data [i] .jobtype +'& lt; / option& gt;');
}
}
});
});
& lt; / script& gt;
& lt; script& gt;
jQuery(document).ready(function()
{
jQuery.ajax(
{
type:'GET',
url:'sample .php',
dataType:'JSON',
成功:函数(数据)
{
for(i = 0; i& lt; jQuery(data).length; i ++)
{
jQuery('#company')。append('& lt; option value ='+ data [i] .company +'& gt;'+ data [i] .company +'& lt; / option& gt;');
}
}
});
});
& lt; / script& gt;
& lt; script& gt;
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(
{
类型:'GET',
url:'search.php',
data:{'jobDetailsData':jsonString},
成功:函数(数据)
{
{
jQuery('#job_listings')。append(data );
}
}
});
});
});
& lt; / script& gt;
& lt; / head& gt;
& lt; body& gt;
& lt; form id =searchname =jobSearch& gt;
& lt; div& gt;
职位类别:& lt; select id =jobcategoryvalue =jobcategory& gt;
& lt; option& gt;选择职位类别& lt; / option& gt;
& lt; / select& gt;& lt; br& gt;& lt; br& gt;
工作类型:& lt; select id =jobtypevalue =jobtype& gt;
& lt; option& gt;选择作业类型& lt; / option& gt;
& lt; / select& gt;& lt; br& gt;& lt; br& gt;
公司:& lt; select id =companyvalue =company& gt;
& lt; option& gt; Select Company& lt; / option& gt;
& lt; / select& gt;& lt; br& gt;& lt; br& gt;
开始日期:& lt;输入类型=日期id =startdatevalue =startdate& gt;& lt; br& gt;& lt; br& gt ;
结束日期:& lt;输入类型=日期id =enddatevalue =enddate& gt;& lt; br& gt;& lt; br& gt ;
工作数量:& lt; select id =jobcountvalue =jobcount& gt;
& lt; option& gt; Select& lt; / option& gt;
& lt; option& gt; 5& lt; / option& gt;
& lt; option& gt; 10& lt; / option& gt;
& lt; option& gt; 15& lt; / option& gt;
& lt; option& gt; 20& lt; / option& gt;
& lt; / select& gt;& lt; br& gt;& lt; br& gt;
& lt; input type =buttonid =submitvalue =Submit/& gt;
& lt; / div& gt;
& lt; div id =job_listingsstyle =class = jobs_list& gt;
& lt; / div& gt;
& lt; / form& gt;
& lt; / body& gt;
& lt; / html& gt;
//这是我的search.php
& lt;?php
mysql_connect(localhost ,根,);
mysql_select_db(plugins);
$ jobDetailsData = json_decode($ _ GET ['jobDetailsData']);
foreach($ jobDetailsData as $ jobDetailsData)
{
$ jobcategory = mysql_real_escape_string($ jobDetailsData-& gt; jobcategory);
$ jobtype = mysql_real_escape_string($ jobDetailsData-& gt; jobtype);
$ company = mysql_real_escape_string($ jobDetailsData-& gt; company);
$ startdate = mysql_real_escape_string($ jobDetailsData-& gt; startdate);
$ enddate = mysql_real_escape_string($ jobDetailsData-& gt; enddate);
$ jobcount = mysql_real_escape_string($ jobDetailsData-& gt; jobcount);
$ result = mysql_query(从job_listings中选择job_title,其中(job_category ='$ jobcategory'或job_type ='$ jobtype'或company_name ='$ company')AND(start_date =' $ startdate'AND_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();
?& gt;
//请帮我这个
解决方案
//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
解决方案
这篇关于如何显示没有。来自MYSQL的项目,基于从Dropdown中选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!