我试图检索选中的复选框,其值存储在数据库中,但他们总是,即使他们在数据库中存在未经检查。 我都试过,但没有奏效,尽管不同的结构相同的代码工作,但对于框架的原因,我需要以此来实现:复选框没有得到遏制
if(isset($sp['Etunimi'])&&isset($sp['Sukunimi'])){
echo "<form method='post' action=''>";
$comp=$this->All_Competences;
echo"<br/>select competences for:".$sp['Etunimi'];
$id=$sp['Id'];
$tmp=array();
if(isset($_POST['select_employee'])){
$cid=$this->cids;
}
foreach($cid as $test)
{
array_push($tmp, $test['c_ID']);
}
for($i=0;$i<count($tmp);$i++){
}
echo "<table><th>valid?</th><th>Competence description</th>";
foreach($comp as $compi){
$checked='';
if(in_array($compi['Competence_ID'],$tmp)){
$checked='checked';
}
echo "<tr><td><input type='checkbox'".$checked."name='c[]' value='".$compi['Competence_ID']."'></td><td>".$compi['Competence_Description']."</td></tr>";
}
echo "</table>";
echo "<input type='hidden' name='action' value='selectchecked'>";
echo "<input type='hidden' name='id' value='".$id."'>";
echo "<input type='submit' value='submit checks'>";
echo "</form>";
所以,当你做'in_array($ compi ['Competence_ID'],$ tmp)){'...你可以退出($ checked);'看看它是否在那里设置?如果没有...几乎知道你的问题在哪里.. – Ohgodwhy 2013-03-20 08:18:09
尝试在'checked'关键字周围放置空格 – 2013-03-20 08:19:47
谢谢Gareth!工作! – auicsc 2013-03-20 08:28:00