国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Article classification sorting function

1, modify the categoryListHtml.php code as follows:

<?php
<!--展示文章分類功能-->
<form method="post" action="?action=order">
    <table border="1" cellpadding="3" cellspacing="0" width="20%">
        <tr bgcolor="skyblue">
            <td align="center">排序</td>
            <td>分類名稱</td>
            <td align="center">操作</td>
        </tr>
        <?php foreach ($category as $v):?>
            <tr>
                <td><input type="text" name="<?php echo $v['id'];?>" value="<?php echo $v['sort'];?>"></td>
                <td><?php echo $v['name'];?></td>
                <td><a href="#">刪除</a>|<a href="">編輯</a> </td>
            </tr>
        <?php endforeach;?>
    </table>
    <div><input type="submit" value="保存排序"></div>
</form>

2, modify the category code: use placeholders to prevent SQL injection Modify the value of the sort field of the database in the way

<?php
elseif ($a="order"){
    $sql="select id from cms_category";
    $result=$db->fetchAll($sql);
    $data=array();
    foreach ($result as $v){
        $data[]=array(
            'id'=>intval($v['id']),
            'sort'=>isset($_POST[$v['id']])?intval($_POST[$v['id']]):0
        );
    }
    $sql="update cms_category set sort=:sort where id=:id";
    $db->data($data)->query($sql,true);
}

3, the display is as follows:

gif5新文件 (3).gif

Database display:

微信圖片_20180306155731.png

Continuing Learning
||
<?php echo "分類排序功能";
submitReset Code