2013-03-12 44 views
0

我正嘗試使用3個複選框創建表單。一個是管理者完成,員工完成和整體完成(如果兩者都被檢查過,或者值爲2)。如果數據庫字段中的值爲2,請選中一個複選框

echo "<td>"."<input type = 'checkbox' name ='employee' value= 'Ecomplete'/>"."</td>"; 
echo "<td>"."<input type = 'checkbox' name ='student' value= 'Scomplete'/>"."</td>"; 
echo "<td>"."<input type = 'checkbox' name ='complete' value= 'complete'/>"."</td>"; 
      echo "</tr>"; 

我所試圖做的是在數據庫中找到的數值,如果它的一個,它仍然是不加制止,如果2複選框被選中。

我的第一個雖然是這樣的:

if($row['manger_complete'] == 1) { checkbox is checked } 
    (not sure how to check a checkbox in php, i'm fairly new) 

我不能讓我的周圍最好的,最簡單的方法頭部做到這一點。

第二個功能是在overall_completion字段中輸入'2',如果員工和經理以及相應的複選框都被檢查。

我知道這是模糊的,但任何幫助將不勝感激我真的卡住了!

回答

0
if($row['manger_complete'] == 1) { 
    echo "<td>"."<input type = 'checkbox' checked='checked' name ='complete' value= 'complete'/>"."</td>"; 
} 
+0

啊哈,這是完美的,它的工作原理雖然現在所有的複選框中除了值爲1的字段外,overall_completion列已經消失。 – stark 2013-03-12 11:47:08

0

這可能會有所幫助:

<input type = 'checkbox' name ='employee' value= 'Ecomplete' <?php if($row['manger_complete'] == 1) echo 'checked = "checked"' ?>/> 
0
$checked = ''; 
if($row['manger_complete'] == 1) { $checked="checked='checked'"; } 
echo "<td>"."<input type = 'checkbox' ".$checked." name ='employee' value= 'Ecomplete'/>"."</td>"; 
echo "<td>"."<input type = 'checkbox' ".$checked." name ='student' value= 'Scomplete'/>"."</td>"; 
echo "<td>"."<input type = 'checkbox' ".$checked." name ='complete' value= 'complete'/>"."</td>"; 
     echo "</tr>"; 
0

從PHP,你有它存在:

echo "<td>"."<input type = 'checkbox' name ='employee' value= 'Ecomplete' ".($row['manager_complete'] == 1 ? "'checked = "checked"'" : "")." />"."</td>"; 
相關問題