简体   繁体   中英

Check a checkbox if value in the database field= 2

I am trying to create a form with 3 checkboxes. One is for manager completion, employee completion and overall completion (if both have been checked, or have a value of 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>";

What I am trying to do is find the numerical value in the database, if its one, it remains unchecked, if its 2 the the checkbox is checked.

My first though was something like:

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

I can't get my head around the best and most simple method to do this.

The second functionality is to enter into the database a '2' in the overall_completion field if both the employee and manager and the checkbox corresponding to be checked.

I know this is vague but any help would be appreciated I'm really stuck!

这可能会有所帮助:

<input type = 'checkbox' name ='employee' value= 'Ecomplete' <?php if($row['manger_complete'] == 1) echo 'checked = "checked"' ?>/>
if($row['manger_complete'] == 1) { 
    echo "<td>"."<input type = 'checkbox' checked='checked' name ='complete' value= 'complete'/>"."</td>";
}
 $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>";

从PHP那里获得:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM