gpt4 book ai didi

php - 使用复选框形式过滤列表(PHP,SQL)?

转载 作者:行者123 更新时间:2023-11-29 22:36:16 24 4
gpt4 key购买 nike

我正在尝试使用复选框和排序表单按 mySQL 表中的变量作业类型过滤来自另一个页面的表单结果。

表中的多次提交已经有工作类型变量,但是当我提交包含所选内容的表单时,提交内容不会显示。

但是,当我不选择任何工作类型复选框时,它们都会显示。

如果我对问题的解释完全不清楚,请随时提问,我会回答任何问题。

<body>
<header>
<a href="testharry.php">Submit a job listing!</a><hr>
<form id="sort" method="post">
<select name="sort" id="sort" onChange="javascript:document.myform.submit();">
<option value="datetime">select</option>
  <option value="jobwage DESC">Wage:Highest to Lowest</option>
  <option value="jobwage">Wage:Lowest to Highest</option>
  <option value="datetime DESC">Time:Recent to Old</option>
  <option value="datetime">Time:Old to Recent</option>
</select><br>
Job type:
<br>
<input type="checkbox" name="jobtypefilter[]" value="industry">Industry<br>
<input type="checkbox" name="jobtypefilter[]" value="accounting_and_finance">Accounting & Finance<br>
<input type="checkbox" name="jobtypefilter[]" value="administration_and_office_support">Administration & Office Support<br>
<input type="checkbox" name="jobtypefilter[]" value="agriculture_and_environment">Agriculture & Environment<br>
<input type="checkbox" name="jobtypefilter[]" value="automotive">Automotive<br>
<input type="checkbox" name="jobtypefilter[]" value="computers_and_technology">Computers & Technology<br>
<input type="checkbox" name="jobtypefilter[]" value="construction">Construction<br>
<input type="checkbox" name="jobtypefilter[]" value="customer_service">Customer Service<br>
<input type="checkbox" name="jobtypefilter[]" value="education">Education<br>
<input type="checkbox" name="jobtypefilter[]" value="food_and_restaurant">Food & Restaurant<br>
<input type="checkbox" name="jobtypefilter[]" value="government_and_military">Government & Military<br>
<input type="checkbox" name="jobtypefilter[]" value="healthcare">Healthcare<br>
<input type="checkbox" name="jobtypefilter[]" value="hotel_and_hospitality">Hotel & Hospitality<br>
<input type="checkbox" name="jobtypefilter[]" value="installation_and_repair">Installation & Repair<br>
<input type="checkbox" name="jobtypefilter[]" value="law_enforcement_and_security">Law Enforcement & Security<br>
<input type="checkbox" name="jobtypefilter[]" value="legal">Legal<br>
<input type="checkbox" name="jobtypefilter[]" value="maintenance_and_janitorial">Maintenance & Janitorial<br>
<input type="checkbox" name="jobtypefilter[]" value="management">Management<br>
<input type="checkbox" name="jobtypefilter[]" value="media_and_entertainment">Media & Entertainment<br>
<input type="checkbox" name="jobtypefilter[]" value="other">Other<br>
<input type="checkbox" name="jobtypefilter[]" value="personal_care_and_services">Personal Care & Services<br>
<input type="checkbox" name="jobtypefilter[]" value="retail">Retail<br>
<input type="checkbox" name="jobtypefilter[]" value="sales_and_marketing">Sales & Marketing<br>
<input type="checkbox" name="jobtypefilter[]" value="salon_spa_fitness">Salon/Spa/Fitness<br>
<input type="checkbox" name="jobtypefilter[]" value="social_services">Social Services<br>
<input type="checkbox" name="jobtypefilter[]" value="transportation">Transportation<br>
<input type="checkbox" name="jobtypefilter[]" value="unknown">Unknown<br>
<input type="checkbox" name="jobtypefilter[]" value="warehouse_and_production">Warehouse & Production<br>
<input type="checkbox" name="jobtypefilter[]" value="wellness">Wellness<br>
<input type="checkbox" name="jobtypefilter[]" value="work_at_home">Work at Home<br>
<input type="submit" value="Submit">
</form>
</header>
<div id='container'>
<?php
$sort=$_POST['sort'];
$jobtypefilter = $_POST['jobtypefilter'];
$con = new PDO('mysql:host=**********;dbname=**********',"***********","**********");
$s = $con->prepare("SELECT * FROM test_kyle ORDER BY $sort");
if (!empty($jobtypefilter))
{
$s = $con->prepare("SELECT * FROM test_kyle ORDER BY $sort WHERE $jobtype=$jobtypefilter");
}
else
{
echo("You didn't select any job types.");
}
$s->execute();
$results = $s->fetchAll();
foreach($results as $listing){
echo "<div class='jobtitle'><h1>".$listing[jobtitle]."</h1></div>";
echo "<div class='jobdescription'><h2>".$listing[jobdescription]."</h2></div>";
echo "<div class='jobtype'><h2>".$listing[jobtype]."</h2></div>";
echo "<div class='hiringmanagername'><p>".$listing[hiringmanagername]."</p></div>";
echo "<div class='hiringmanagerphone'><p>".$listing[hiringmanagerphone]."</p></div>";
echo "<div class='jobwage'><p>".$listing[jobwage]."</p></div>";
echo "<div class='jobaddress'><p>".$listing[jobaddress]."</p></div>";
echo "<div class='jobapplicationlink'><p>".$listing[jobapplicationlink]."</p></div>";
echo "<div class='datetime'><p>".$listing[datetime]."</p></div>";
}
$con = null;

?>
</body>

最佳答案

检查此代码

$jobTypeFilter=implode(",", $_POST['jobtypefilter']);
$s = $con->prepare("SELECT * FROM test_kyle ORDER BY $sort WHERE FIND_IN_SET('".$jobtype."','".$jobTypeFilter."');

关于php - 使用复选框形式过滤列表(PHP,SQL)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29527577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com