[991]PHP網站開發 進階應用技巧2
<?php
$root_pass="12345"; //資料庫root密碼
$db_name="test"; //資料庫名稱
/* 連資料庫檢查 */
$link=mysql_connect("localhost","root",$root_pass); //資料庫連線
mysql_select_db("test");
mysql_query("SET NAMES 'utf8'"); //設定語系
error_reporting(0);
if($_POST['op']=="save_sort"){
$sort=1;
foreach($_POST['new_sort'] as $sn=>$v){
$sql="update web set sort='$sort' where sn='$sn'";
mysql_query($sql);
$sort++;
}
}
$sql="select * from web order by sort";
$result=mysql_query($sql);
$main="";
while(list($sn,$title,$url,$sort)=mysql_fetch_row($result)){
$main.="<tr><td>$sn</td><td>$title</td><td>$url</td><td>$sort
<input type='hidden' name='new_sort[$sn]'></td></tr>";
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
<link rel="stylesheet" href="tinytable.css" />
</head>
<body>
<style>
.aa{
color: yellow;
background-color: black;
}
</style>
<script type='text/javascript' src='jquery-1.4.2.min.js'></script>
<script type='text/javascript' src='jquery.tablednd_0_5.js'></script>
<script type='text/javascript'>
$(document).ready(function(){
$('#tbl').tableDnD({
onDragClass: "aa" ,
onDragStart:function(){
$("#saveArea").html("<input type='hidden' name='op' value='save_sort'><input type='submit' value='儲存'>");
}
});
});
</script>
<form action="index.php" method="post">
<table id="tbl" class="tinytable">
<thead>
<tr>
<th><h3>編號</h3></th>
<th><h3>網站名稱</h3></th>
<th><h3>網址</h3></th>
<th><h3>排序</h3></th>
</tr>
</thead>
<tbody>
<?php echo $main; ?>
</tbody>
</table>
<div id="saveArea" align="center"></div>
</form>
</body>
</html>