默认情况下,在PHP中的特定表下对列表进行排序(Sort a list by default under specific table in PHP)

编程入门 行业动态 更新时间:2024-10-28 19:26:59
默认情况下,在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);

更多推荐

本文发布于:2023-08-07 23:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466477.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:情况下   列表   PHP   Sort   table

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!