如何使用php mysql在数据库中向上移动行?

时间:2016-10-07 08:29:25

标签: php mysql

/// SQL Query

CREATE DATABASE IF NOT EXISTS `move_row` 
USE `move_row`;

CREATE TABLE IF NOT EXISTS `tbl_cate` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `ordering` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;


INSERT INTO `tbl_cate` (`id`, `name`, `ordering`) VALUES
    (1, 'a', 1),
    (2, 'b', 2),
    (3, 'c', 3),
    (4, 'd', 4),
    (5, 'e', 5),
    (6, 'f', 6);


/// My code    

<?php 
    mysql_connect("localhost","root","") or die(mysql_error());
    mysql_select_db("move_row");
?>
<table width="100%">
    <tr>
        <th>N</th>
        <th>Name</th>
        <th>Ordering</th>
    </tr>
    <?php 
        $query = mysql_query("SELECT * FROM tbl_cate ORDER BY ordering ASC");
        while($rows = mysql_fetch_array($query)){
    ?>
    <tr>
        <td><?php echo $rows['id'] ;?></td>
        <td><?php echo $rows['name'] ;?></td>
        <td>
            <a href="index.php?action=move_up&move_up_id<?php echo $rows['id'];?>">Up</a>
            <a href="index.php?action=move_down&move_down_id<?php echo $rows['id'];?>">Down</a>
        </td>
    </tr>
    <?php } ?>
</table>

<?php
    if(isset($_GET['action']) && ($_GET['action'] =="move_up")){

            //// please help

    }else if(isset($_GET['action']) && ($_GET['action'] =="move_down")){

            //// please help
    }
?>

0 个答案:

没有答案