Hi again,
I don't think I explained my problem well enough and I didnt include enough of my code...
When I use the code as a standalone script it works fine but when I add it to my WordPress website it stops saving to the database.
I have since realised that where the problem is but I don't know what the problem is
I have highlighted in "
red" where the problem is:
Main Code:
Code:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-ui-1.8.13.custom.min.js"></script>
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function() {
$j("#test-list").sortable({
handle : '.handle',
update : function () {
var homepageorder = $j('#test-list').sortable('serialize');
alert('variable is: ' + homepageorder + '');
$j("#test-info").load("process-sortable.php?"+homepageorder);
}
});
});
</script>
<pre>
<div id="test-info">Waiting for update</div>
</pre>
<ul id="test-list">
<li id="listItem_1"><img src="arrow.png" alt="move" width="16" height="16" class="handle" /><strong>Item 1 </strong></li>
<li id="listItem_2"><img src="arrow.png" alt="move" width="16" height="16" class="handle" /><strong>Item 2</strong></li>
<li id="listItem_3"><img src="arrow.png" alt="move" width="16" height="16" class="handle" /><strong>Item 3</strong></li>
<li id="listItem_4"><img src="arrow.png" alt="move" width="16" height="16" class="handle" /><strong>Item 4</strong></li>
</ul>
process-sortable.php
Code:
<?php
$dbhost = "*********";
$dbuser = "*********";
$dbpass = "*********";
$dbname = "*********";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Error connecting to mysql");
mysql_select_db($dbname);
foreach ($_GET['listItem'] as $position => $item) :
$query = "UPDATE `homepageorder` SET `position` = $position WHERE `id` = $item";
mysql_query($query) or die('Error, insert query failed');
$sql[] = "UPDATE `homepageorder` SET `position` = $position WHERE `id` = $item";
endforeach;
print_r ($sql);
?>
I know that this code wont reorder the list as I am not retrieving the order from the database but it should update the database fields and it isnt.
All I can figure out is that there is a problem somewhere between the "update" function and the "process-sortable.php" file as everything else works and I even get the alert showing the new variable order so I know the update function is running.
Thanks again for any help you can give me.