使用echo中的复选框作为表

时间:2017-01-18 14:18:57

标签: php

我有一个回显表的代码:

<?php


// connect to the database
include('core/base.php');

// get results from database
$result = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM uitslag ORDER BY ID ASC") 
    or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));  

// display data in table


echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>Nummer</th><th>Naam</th><th>Telefoon</th><th>Binnen</th> <th>Adres</th> <th>Postcode</th> <th>Wijk</th></tr>";

// loop through results of database query, displaying them in the table
while($row = mysqli_fetch_array( $result )) {

    // echo out the contents of each row into a table
    echo "<tr>";
    echo '<td>' . $row['ID'] . '</td>';
    echo '<td>' . $row['Naam'] . '</td>';
    echo '<td>' . $row['Telefoon'] . '</td>';
    echo '<td>' . $row['Binnen'] . '</td>';
    echo '<td>' . $row['Adres'] . '</td>';
    echo '<td>' . $row['Postcode'] . '</td>';
    echo '<td>' . $row['Wijk'] . '</td>';
    echo '<td><a href="edit.php?id=' . $row['ID'] . '">Aanpassen</a></td>';
    echo "</tr>"; 
} 

// close table>
echo "</table>";

&GT;

“Telefoon”行可以回显1或0.如何回显1时检查的复选框,而不是回显实际数字?

2 个答案:

答案 0 :(得分:0)

 <?php 
     if($row['Telefoon']==1){
        echo "<td><input type='checkbox' checked></td>";
     }
     else {
        echo "<td><input type='checkbox' ></td>";
     }
?>

答案 1 :(得分:0)

定义类型为checkbox的输入元素。就像这样。

$telefoon = ($row['Telefoon']==1)?'checked':'';
echo '<td>' . $row['ID'] . '</td>';
echo '<td>' . $row['Naam'] . '</td>';
echo "<td><input type='checkbox' $telefoon></td>";
echo '<td>' . $row['Binnen'] . '</td>';
echo '<td>' . $row['Adres'] . '</td>';
echo '<td>' . $row['Postcode'] . '</td>';
echo '<td>' . $row['Wijk'] . '</td>';