我试图创建一个搜索页,将有能力通过特殊技能搜索候选人。
前面有多个技能复选框。我使用此函数将复选框值存储为逗号分隔值:
HTML
<table border="0" cellpadding="1" cellspacing="0">
<tbody><tr>
<td align="left"><input value="Arts" id="expert_1" name="experts[]" type="checkbox"><label for="expert_1"><span>Arts & Performing Arts </span></label></td>
<td align="left"><input value="Environment" id="expert_4" name="experts[]" type="checkbox"><label for="expert_4"><span>Environment </span></label></td>
<td align="left"><input value="Religious" id="expert_7" name="experts[]" type="checkbox"><label for="expert_7"><span>Religious</span></label></td>
</tr>
<tr>
<td align="left"><input value="Associations" id="expert_2" name="experts[]" type="checkbox"><label for="expert_2"><span>Associations</span></label></td>
<td align="left"><input value="Foundation" id="expert_5" name="experts[]" type="checkbox"><label for="expert_5"><span>Foundation</span></label></td>
<td align="left"><input value="Social Services" id="expert_8" name="experts[]" type="checkbox"><label for="expert_8"><span>Social Services</span></label></td>
</tr>
<tr>
<td align="left"><input value="Education" id="expert_3" name="experts[]" type="checkbox"><label for="expert_3"><span>Education</span></label></td>
<td align="left"><input value="Health Care" id="expert_6" name="experts[]" type="checkbox"><label for="expert_6"><span>Health Care</span></label></td>
<td> </td>
</tr>
</tbody></table>PHP
$experts = $_POST['experts'];
$chk = '';
foreach($experts as $expert)
{
$chk .= $expert.",";
} 我将$chk存储在数据库中。
现在,如何从数据库中检索其访问字段已选中的用户?
发布于 2016-05-30 16:36:27
您的数据库结构不适合这样的查询。
我想不出一个可行的方法来实现使用SQL查询,你应该从数据库中检索所有记录,然后在php中选择值,但这是一个非常糟糕的情况: php检查比数据库检查慢得多。
你不能在你的数据库中为每个复选框添加一个布尔值字段吗?这将是一个更好的数据库结构,它将使您的查询更加容易
https://stackoverflow.com/questions/37521019
复制相似问题