2014-02-06 125 views
-7

我做一个PHP页面我要附加与列表框选项值复选框我如何连接复选框,这里是我的代码:如何添加复选框在PHP中的选择选项?

<select name="recepients[]" multiple size="10" multiple="multiple" > 
    <? 
     //echo $eventid=$_POST['events']; 
     $count=count($_POST['events']); 
     for($i=0; $i<$count; $i++){ 
      $select="select b.first_name,b.last_name from buyers b,registrations r where b.buyer_id=r.buyer_id and r.event_id='".$_POST['events'][$i]."' group by r.buyer_id"; 
      $res = $GLOBALS ['mysqli']->query ($select) or die ($GLOBALS ['mysqli']->error . __LINE__); 
      if ($res->num_rows > 0) 
      {   
       while($row = $res->fetch_assoc()) 
       { 
       ?> 
       <input type="checkbox" name="receptionts[]" checked="checked"/> 
       <option value="<?=$row['first_name']?>"><?=$row['last_name']?></option> 
       <? 
       } 
      } 
     } 
     ?> 
</select> 
+0

你所说的“重视”是什么意思? –

+0

我的意思是选项值有复选框,其始终选择 –

+0

所以你想有一个默认选项? – elitechief21

回答

1

我不知道我明白把复选框放在列表中的原理。
如果这是选择所有的默认项,您可以使用列表multipe与选项标签

selected选项
<select multiple size="10"> 
... 
    <option selected="selected" value="<?=$row['first_name']?>"><?=$row['last_name']?></option> 
.... 

好运:)

0

好吧,你可以在你的数据库中包含selected=selected如果一个字段希望它被选中。然后echo $row['selected']

+0

但我没有在数据库中创建任何字段另一个解决方案将优先 –

+0

再次看到我的代码 –

相关问题