Hi, apologies if I'm missing something obvious...

I am dynamically generating lists in php each of which needs to be
sortable and saves the new order back to MySQL via an Ajax call.

All the parts are in place, apart from I cannot work out how to avoid
using a hard-coded element id in the PHP code to loop through the
array - it needs to be dynamically passed in.

So... code builds a series of <ul> with unique id and then:

<script type="text/javascript">
  var list = frmEditShopList.getElementsByTagName('ul');
  for(i=0;i<list.length;i++){
    Sortable.create(list[i].id,
{dropOnEmpty:true,constraint:false,onUpdate:updateOrder});
  }
</script>

handles the variable number of Sortable.create calls. I then make the
Ajax call to a PHP page:

function updateOrder(list){
  var url = '/common/script/update-order.php';
  var params = Sortable.serialize(list.id);
  var ajax = new Ajax.Request(url,{method:'post',parameters:params});
}

and this is the bit I'm stuck with. I have done this before with a
single list:

$order = 1;
foreach ($_POST['list'] as $itemid) {
  $sql = "UPDATE shop_items SET item_order = $order WHERE pkShopItemID
= $itemid";
  $result = do_query($sql);
  $order++;
}

but how can I replace the $_POST['list'] with a dynamic element id? Is
there a parameter to the Ajax object that can store the id of the
submitted element??


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to