Jump to content

Drag n drop not saving to database


richrock

Recommended Posts

Hi,

 

using the excellent scriptalicious library, I've decided to use this to allow dynamic listing/saving of items prior to printing a catalogue.  However, it's not saving the updated list.

 

This is compounded by the fact that there are several catalogues in the table (referred by 'cat').  So I've add the cat row to the sql commands, but still no dice.  What I would like to do is refresh the list with the new lot numbers :

 

here is my main page:

 

<?php

if($_POST['LotSort']) {

echo "Sort Lots";
?>
<?php

$sql = "select * from jos_bid_auctions where cat=1002 order by 'lot_num'";
$result = mysql_query($sql)or die(mysql_error());
$number = mysql_num_rows($result);
for($x=1;$x<=$number;$x++){
$row = mysql_fetch_array($result);
$list.= "		 <li id=\"item_$row[lot_num]\">ID: $row[id], Lot No: $row[lot_num], <strong>$row[title]</strong>, £$row[est_low]-£$row[est_high]</li>\n";
}
?>

	<script type="text/javascript" src="prototype-1.6.0.2.js"></script>
	<script type="text/javascript" src="scriptaculous/src/scriptaculous.js"></script>

	<style type = "text/css">
		ul#sortlist{list-style:none;padding:0px;margin:0px}
		ul#sortlist li{padding:5px;border:1px solid #666666;margin:1px;font:normal 10px verdana;width:500px;color:#666666;background-color:#f0f0f0;cursor:move}
		#output{font:bold 10px verdana}
	</style>
<ul id = "sortlist">

	<?php echo $list; ?>

</ul>



		<script type="text/javascript">

			Sortable.create('sortlist',{

				onUpdate:function(){
				new Ajax.Updater('output','sort.php',{onComplete:function(request){}, parameters:Sortable.serialize('sortlist'), evalScripts:true, asynchronous:true})

				}

			})

		</script>
<?php

// End of cataloguing
}

?>

 

and the sort.php :

 

<?php

$connection = mysql_connect ("localhost", "root", "root");
$db= mysql_select_db("bromp-admin",$connection);

debugMe();

print_r($_POST[sortlist]);

foreach ($_POST[sortlist] as $varname => $varvalue) {

echo "VarName: ".$varname;
echo " - ";
echo "VarValue: ".$varvalue."<br />";

$sql = "UPDATE jos_bid_auctions SET id = ".mysql_real_escape_string($varname)." WHERE id = ".mysql_real_escape_string($varvalue)." AND cat = 1002";
$result = mysql_query($sql) or die(mysql_error());
}
echo "You just updated it on ".date("Y-m-d H:i:s");
?>

 

I've looked and looked.  I even get the last line "You just updated..." as correct, but reloading the page shows the original order.  Sure I'm missing something, but Ajax is new to me.

 

R

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.