有没有办法显示表格内容像网格没有滚动

时间:2016-02-22 10:11:00

标签: php html mysql

我想将show复选框作为网格而不滚动页面。我正在开发一个出勤报告页面,其中显示了学生姓名和带有数据库值的复选框。我想在这样的网格中显示它:

this

我的代码显示如下:

this

我的代码:

<table border="1" cellspacing="2" cellpadding="5" summary="">
<?php 
    while ($row = mysql_fetch_assoc($res)){?>
    <th>
      <input type="checkbox" class="input" id="input
         <?php echo $row['st_id']; ?>"
         name="student[]" value="<?php echo $row['st_id']; ?>" 
         checked="checked"   >
         <?php echo $row['st_name'] ; ?>
         <label for="input<?php echo $row['st_id']; ?>">
         </label>
    </th>

此代码从数据库中获取名称和复选框ID。任何人请帮助

2 个答案:

答案 0 :(得分:1)

您可以使用浮动DIV而不是表格:

    <style>
        .inputDiv{
            float: left;
            padding: 5px;
            margin: 5px;
            border: 1px solid black;
        }
    </style>
    <?php while ($row = mysql_fetch_assoc($res)) { ?>
        <div class="inputDiv">
            <input type="checkbox" class="input" id="input<?php echo $row['st_id']; ?>"  name="student[]" value="<?php echo $row['st_id']; ?>" checked="checked"   > <?php echo $row['st_name']; ?> 
            <label for="input<?php echo $row['st_id']; ?>"></label>
        </div>
    <?php } ?>

这将根据用户的屏幕分辨率自动重新排序所有DIV。

答案 1 :(得分:1)

你可以像这样使用它:

<table border="1" cellspacing="2" cellpadding="5" summary="">
<?php 
$counter = 1;
while ($row = mysql_fetch_assoc($res)){
    if($number==1 ) {
        echo '<tr>';
    } 
    if($number %6 == 0) {
        echo '</tr><tr>';   
    }
?>
<th> <input type="checkbox" class="input" id="input<?php echo $row['st_id']; ?>"  name="student[]" value="<?php echo $row['st_id']; ?>" checked="checked"   > <?php echo $row['st_name'] ; ?> <label for="input<?php echo $row['st_id']; ?>"></label></th>
<?php 
$counter++;
if($number==0 || $number %6 == 0) {
        echo '</tr>';
    } 
}
?>
</tr>
</table>
相关问题