晚上好,我正在开发一个项目,其中包含一个用户可以选择的七个选项列表。我试图让他们所有人用逗号介于两者之间。这不是从数据库中提取,而是从PHP表单中提取。
<html>
<tr><td><font color=black>Select all Constituency Groups that apply:</font></td></tr>
<tr><td><b><hr size=0 color=silver noshade></b></td></tr>
<tr><td><input value="1st Year Student" type="checkbox" name="chkCon[]" id="ChkCon1" /> 1st Year Student</font></td></tr>
<tr><td><input value="2nd Year Student" type="checkbox" name="chkCon[]" id="ChkCon2" /> 2nd Year Student</font></td></tr>
<tr><td><input value="4 Year College Professor" type="checkbox" name="chkCon[]" id="ChkCon3"/> 4 Year College Professor</font></td></tr>
<tr><td><input value="Adjunct Faculty" type="checkbox" name="chkCon[]" id="ChkCon4" /> Adjunct Faculty</font></td></tr>
<tr><td><input value="Alumni/Graduate" type="checkbox" name="chkCon[]" id="ChkCon5"/> Alumni/Graduate</font></td></tr>
<tr><td><input value="High School Teacher" type="checkbox" name="chkCon[]" id="ChkCon6" /> High School Teacher</font></td></tr>
<tr><td><input value="Industry Representative" type="checkbox" name="chkCon[]" id="ChkCon7" /> Industry Representative</font></td></tr>
</table>
</html>
我不确定我是否需要将它们命名为相同或不同。但这里是帖子
if (!empty($_REQUEST['chkCon[]'])) {
$ChkCon = $_REQUEST['chkCon[]'];
} else {
$ChkCon = "";
}
谢谢
答案 0 :(得分:0)
$chkCon = $_REQUEST['chkCon'];
$values = "";
for ($i=0;$i<count($chkCon);$i++) {
$values .= $chkCon[$i];
if ($i<count($chkCon)-1) {
$values .= ",";
}
}
echo $values;