【发布时间】:2014-05-13 21:41:19
【问题描述】:
我有一份商务经理职位的候选人名单。选民需要选择至少两名候选人。我使用复选框是为了让选民可以进行多项选择。 And when the voter clicks on next button to proceed voting to other positions , the two selected Business Manager should be carried..The problem is I can get the two but with the same Name.
例如:选民被选中
John Smith and Harry Potter
我得到值时的结果只是最后一个被选中的人。我注意到在我的收件箱中我只使用了一个 name="choice" 所以不可能得到两个....当我的列表是静态的时,我不能为每个收件箱分配不同的名称,但在我的情况下,我使用了动态方式将它们放在复选框数组中,这意味着它们具有相同的 name="choice"...希望您理解我的意思...请帮助我..以下是我的代码实现..
-
填充复选框列表的结果:
$result = mysql_query($QUERY); while($row = mysql_fetch_object($result)){ $Name = $row->Name; $PLName = $row->PLName; $CID = $row->CID; echo '<tr><td>'; echo '<img src="fetchImage.php?CID=' . $CID . ' " alt="Candidate photo" width="150px" height="135px" style="border:2px solid silver;">'; echo '</td>'; echo '<td><div class="contact_info_title">' . $Name . '</div><br>'; echo $PLName . '<br><br>'; if(isset($_SESSION['VLPCCBusManager'])){ if($_SESSION['VLPCCBusManager'] == $CID){ echo '<input type="checkbox" name="Choice" value=' . $CID . ' Checked>Select </td></tr>'; }else{ echo '<input type="checkbox" name="Choice" value=' . $CID . '>Select </td></tr>'; } }else{ echo '<input type="checkbox" name="Choice" value=' . $CID . '>Select </td></tr>'; } } echo ''; -
点击提交时获取选择的选项移动到另一个表单:
if(isset($_POST['submit'])){ if(isset($_POST['Choice'])){ if(empty($_POST['Choice'])){ $errors='Choice'; } if(empty($errors)){ $Choice = $_POST['Choice']; $_SESSION['VLPCCBusManager'] = $Choice; $_SESSION['VLPCCBusManager2'] = $Choice; header("Location: VLPCCSgtArms.php?ChoiceCat=$ChoiceCat"); } }else{ $_SESSION['VLPCCBusManager'] = '0'; $_SESSION['VLPCCBusManager2'] = '0'; header("Location: VLPCCSgtArms.php?ChoiceCat=$ChoiceCat"); }}
【问题讨论】:
标签: php session select checkbox