我有这个页面(下面的代码),其中包含一系列 5 个复选框,都代表不同的值,我需要使用它们来查询数据库。
<form id="form1" name="form1" method="post" align="center" action="section_search_results1.php">
<p>Select The <b>Section</b> You Wish To Search In Below... </p>
<p>
<label for="section"></label>
<label for="section2"></label>
<label>
<input type="checkbox" name="SectionSelect" value="Functional" id="SectionSelect_0" />
Functional</label>
<label>
<input type="checkbox" name="SectionSelect" value="Technical" id="SectionSelect_1" />
Technical</label>
<label>
<input type="checkbox" name="SectionSelect" value="Commercial" id="SectionSelect_2" />
Commercial</label>
<label>
<input type="checkbox" name="SectionSelect" value="Implementation" id="SectionSelect_3" />
Implementation</label>
<label>
<input type="checkbox" name="SectionSelect" value="Innovation" id="SectionSelect_4" />
Innovation</label>
<br />
</p>
<p>Enter the <b>Keyword(s) or Keyphrase</b> Below...</p>
<p>
<label for="kword"></label>
<input type="text" name="kword" id="kword" placeholder="Enter Keyword(s)" />
<br />
</p>
<p>
<input type="submit" name="submit" id="submit" value="Search" /> | | <input type="reset" name="clear" id="clear" value="Clear" />
</p>
</form>
如您所见,每个都有自己的值,即用于查询数据库的术语。结果页面的php查询代码如下
<?php
$kword = $_POST["kword"];
$section = $_POST["SectionSelect"];
function boldText($text, $kword) {
return str_ireplace($kword, "<strong>$kword</strong>", $text);
}
// Connects to your Database
mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
mysql_real_escape_string($kword);
$data = mysql_query("select company_name, section_name, question, answer from company, rfp, section, question_keywords
where company.company_id = rfp.company_id
and rfp.rfp_id = question_keywords.rfp_id
and question_keywords.section_id = section.section_id
and section_name like '%$section%'
and keywords like '%$kword%';")
or die(mysql_error());
?>
最终我想要做的是使用查询来查询数据库,以便可能为每个复选框值提供 where 子句?例如,我想选择 x 其中 y 喜欢 'Technical' 和 y 喜欢 'Functional' 等等...
任何帮助都会很棒
谢谢