在开发项目中,我们会经常碰到文章排序功能,也就是把优秀的文章推荐到前面。
PHP
<table width="100%" cellspacing="0" cellpadding="0" border="0" class="table_parameters">
<tbody>
<tr class="tr_head">
<td>用户名</td>
<td>内容</td>
<td width="120px">排序</td>
</tr>
<?php
$sql = "SELECT name,content,id,ord FROM wishing_wall ORDER BY ord ASC limit 0,10 ";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
?>
<tr>
<td align="center"><?php echo $row['name']; ?></td>
<td><?php echo $row['content']; ?></td>
<td align="center"><a onclick="changeOrd($(this), '<?php echo $row['id']; ?>')"><?php echo $row['ord']; ?></a></td>
</tr>
<?php } ?>
</tbody>
</table>
JS
function changeOrd(obj, id) {
var val = obj.text();
var c = obj.parent("td");
obj.parent("td").html("<input type='text' style='width:50px;' onFocus=this.select() onblur=changeOrdConfirm($(this)," + id + ") value='" + val + "' />");
c.children("input").focus();
}
function changeOrdConfirm(obj, id) {
var ord = obj.val();
$.post("ajax.php", {
id: id,
ord: ord
},
function(data) {
obj.parent("td").html("<a onclick=changeOrd($(this)," + id + ")>" + obj.val() + "</a>");
})
}
ajax.php
include_once("connect.php");
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
$ord = isset($_POST['ord']) ? intval($_POST['ord']) : 0;
if ($id > 0) {
$sql = "UPDATE `wishing_wall` SET `ord` = '".$ord."' WHERE `id` = '" . $id . "';";
mysql_query($sql);
}
系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791