默认情况下,在PHP中的特定表下对列表进行排序(Sort a list by default under specific table in PHP)
我目前有一个很长的列表,由PHP从MySQL生成。 它有3列,它的HTML看起来大致如下:
<thead> <tr> <th style="display:none;">IP</th> <th>ID</th><th>Status</th> <th>Selection</th> </tr> </thead> <tbody> <?php while($a = $ks->fetch(PDO::FETCH_ASSOC)) { ?> <tr> <td style="display:none;"><?php echo $a['ip'];?></td> <td><?php echo $a['id'];?></td> <td><?php echo getstatus($a['status']);?></td> <td><input type="checkbox" data-status="<?php echo getstatus($a['status']);?>" onclick="redes(this)" value="<?php echo $a['ip'];?>"></td> </tr> <?php }?>现在,在TH文本旁边的每个表格列中都有2个箭头(一个向上和向下),您可以相应地对它们进行排序。 我想知道在访问页面时我默认如何将一行排序ASC?
I currently have a long list that is being generated by PHP from a MySQL. It has 3 columns and the HTML for it looks roughly like:
<thead> <tr> <th style="display:none;">IP</th> <th>ID</th><th>Status</th> <th>Selection</th> </tr> </thead> <tbody> <?php while($a = $ks->fetch(PDO::FETCH_ASSOC)) { ?> <tr> <td style="display:none;"><?php echo $a['ip'];?></td> <td><?php echo $a['id'];?></td> <td><?php echo getstatus($a['status']);?></td> <td><input type="checkbox" data-status="<?php echo getstatus($a['status']);?>" onclick="redes(this)" value="<?php echo $a['ip'];?>"></td> </tr> <?php }?>Now, in every table column next to the TH text there are 2 arrows (one up and down) and you can sort them accordingly. I want to know how I can have one row sorted ASC by default when visiting the page?
最满意答案
例如。
<?php $sort = $_GET['sort'] ?: 'ip'; $sql = 'SELECT ip,status,section FROM tab ORDER BY '. $sort; $ks = $db->query($sql);eg.
<?php $sort = $_GET['sort'] ?: 'ip'; $sql = 'SELECT ip,status,section FROM tab ORDER BY '. $sort; $ks = $db->query($sql);更多推荐
发布评论