2015-04-17 44 views
0

我拥有数据库设置权限YES如果用户有权访问此权限如果用户无权访问此权限,则为否。我想根据是否勾选某个用户的复选框来更改这些答案。我希望YES答案显示为勾选复选框,而No答案显示为空白复选框。我该如何做到这一点,因为我的数据库目前正在输出YES或NO作为用户的结果。将数据库信息显示为复选框

<?php 
    $servername = "localhost"; 
    $username = "username"; 
    $password = "password"; 
    $dbname = "databasename"; 

    // Create connection 
    $conn = new mysqli($servername, $username, $password, $dbname); 
    // Check connection 
    if ($conn->connect_error) { 
     die("Connection failed: " . $conn->connect_error); 
    } 

    $sql = "SELECT adduser, edituser, removeuser, unlockallfiles, viewlocked, filepermissions FROM departments"; 
    $result = $conn->query($sql); 

    if ($result->num_rows > 0) { 
     echo "<table class='table table-hover'><tr style='font-size:18px;'><th>Add User</th><th>Edit User</th><th>Remove User</th><th>Unlock All</th><th>View Locked</th><th>File Permissions</th></tr>"; 
     // output data of each row 
     while($row = $result->fetch_assoc()) { 
      echo "<tr style='font-size:16px;'><td>".$row["adduser"]."</td><td>".$row["edituser"]."</td><td>".$row["removeuser"]."</td><td>".$row["unlockallfiles"]."</td><td>".$row["viewlocked"]. "</td><td>" .$row["filepermissions"]. "</td></tr>"; 
     } 
     echo "</table>"; 
    } else { 
     echo "There are 0 clients in the system matching your search criteria"; 
    } 
    $conn->close(); 
?> 

如何获取数据YES显示为打钩复选框,否则显示为空复选框?

回答

1

更换相应的在你的代码行与下面的一个:

// output data of each row 
    while($row = $result->fetch_assoc()) 
    { 
     echo "<tr style='font-size:16px;'>"; 
     echo "<td><input type='checkbox'". ($row["adduser"] == 'Yes' ? " checked" : "") ."></td>"; 
     echo "<td><input type='checkbox'". ($row["edituser"] == 'Yes' ? " checked" : "") . "></td>"; 
     echo "<td><input type='checkbox'". ($row["removeuser"] == 'Yes' ? " checked" : "") . "></td>"; 
     echo "<td><input type='checkbox'". ($row["unlockallfiles"] == 'Yes' ? " checked" : "") ."></td>"; 
     echo "<td><input type='checkbox'". ($row["viewlocked"] == 'Yes' ? " checked" : "") . "></td>"; 
     echo "<td><input type='checkbox'". ($row["filepermissions"] == 'Yes' " checked" : "") . "></td>"; 
     echo "</tr>";         
    } 
+0

非常完美三江源! – DGTLSS

0
echo "<tr style='font-size:16px;'><td>".($row["adduser"]=='Yes'?'<input type="checkbox" checked/>':'<input type="checkbox"/>')."</td><td>".($row["edituser"]=='Yes'?'<input type="checkbox" checked/>':'<input type="checkbox" />')."</td><td>".($row["removeuser"]=='Yes'?'<input type="checkbox" checked/>':'<input type="checkbox"/>')."</td><td>".($row["unlockallfiles"]=='Yes'?'<input type="checkbox" checked/>':'<input type="checkbox"/>')."</td><td>".($row["viewlocked"]=='Yes'?'<input type="checkbox" checked/>':'<input type="checkbox"/>'). "</td><td>" .($row["filepermissions"]=='Yes'?'<input type="checkbox" checked/>':'<input type="checkbox"/>'). "</td></tr>"; 
相关问题