Witam!
Znalazłem w internetach sposób na sortowanie rekordów w SQLu przy użyciu javascriptu, konkretniej jQuery - konkretniej metodą drag & drop. Mój kod teraz wygląda ta:
Plik kolejnosc.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jQuery Sortable With AJAX & MYSQL</title>
<script src="jquery-1.3.2.min.js"></script>
<script src="jquery-ui-1.7.1.custom.min.js"></script>
<link rel='stylesheet' href='styles.css' type='text/css' media='all' />
<link rel='stylesheet' href='style.css' type='text/css' media='all' />
<script type="text/javascript">
// When the document is ready set up our sortable with it's inherant function(s)
$(document).ready(function() {
$("#test-list").sortable({
handle : '.handle',
update : function () {
var order = $('#test-list').sortable('serialize');
$("#info").load("kolejnosc2.php?"+order);
}
});
});
</script>
</head>
<body>
<?
if(!$query0){
}
else{
}
<div id='info'>Waiting for update</div>
</pre>
<ul id='test-list'>";
{
echo "<li id='listItem_".$row[0]."'><img src='arrow.png' alt='move' width='16' height='16' class='handle' /><strong>".$row[1]."</strong></li>"; }
echo "<form action='kolejnosc2.php' method='post' name='sortables'> <input type='hidden' name='test-log' id='test-log' />
<input type='submit' />
</form>";
?>
</body>
</html>
Plik kolejnosc2.php
<?php
if(!$query0){
}
else{
}
foreach ($_GET['listItem'] as $position => $item){
$sql=mysql_query("UPDATE podstrony SET id=$item WHERE id=$position"); echo "<br>".$item."<br>".$position."<br><br>"; }
?>
A problem polega na tym, że kod niby działa ale nie ma przełożenia do sql'a. Mógłbym prosić o wskazówki? (IMG:
style_emoticons/default/smile.gif)
Ten post edytował student229d 12.11.2014, 17:25:23