Try this: put a print_r($_POST) in your handler, and look at what gets
posted to the server in Firebug. I don't think that what you're doing
here (exploding by _) is meaningful at all.
The data generated by Sortable.serialize looks like this after PHP
grabs it from the POST:
whatever_your_list_ID_is = Array(
0 => 12,
1 => 13,
2 => 24,
3 => 2,
4 => 42
)
The keys of the array give the position, the values give the numerical
part of the list item ID. So in this case, the list looked like this
in the DOM when serialize() wrapped it up:
<ul id="whatever_your_list_ID_is">
<li id="item_12"> ... </li>
<li id="item_13"> ... </li>
<li id="item_24"> ... </li>
<li id="item_2"> ... </li>
<li id="item_42"> ... </li>
</ul>
If you drag the list around some more, the array reported would be
different, but the structure would be identical.
In PHP, you could do something this simple:
foreach($_POST['whatever_your_list_ID_is'] as $k=>$v){
if($product = ActiveRecord::FindById('products',$v)) {
$product->position = $k+1;
$product->save();
}
}
This example is using the MyActiveRecord class, which is a nice
(disclaimer, I wrote small parts of it, maintain it) implementation of
Martin Fowler's Active Record pattern in PHP. In this example, there
is a position column in the database which is used as a sort key by
your display code, and updated in this loop to give the new sort order.
I've posted more about this in the list before, here's one I found by
searching this group in the Google Groups interface:
http://groups.google.com/group/prototype-scriptaculous/browse_thread/thread/bc4ae3bb1a06328e/1e29ce690e08366f?hl=en&lnk=gst&q=update+sort+order+PHP#1e29ce690e08366f
Walter
On Jun 8, 2009, at 6:28 AM, WLQ wrote:
>
> It helped :)
>
> Here I've created an update_order.php
> Can you please troubleshoot it?
> http://jsbin.com/apono
>
>> Add a closing parenthesis and a semicolon after the closing brace at
>> the end of line 77 of the code on jsbin.
>>
>> Here it is in context:
>>
>> //this replaces the call to Prototype's identify()
>> function
>> clone.id = transport.responseText;
>> }}); <-- right here
>>
>> //re-build the list to include the new cloned element
>> setupSortable.defer();
>>
>> Walter
>>
>> On Jun 6, 2009, at 2:55 PM, WLQ wrote:
>>
>>
>>
>>> missing ) after argument list
>>> setupSortable.defer();\n
>>
>>> That's by your
>>> http://jsbin.com/emuya/edit
>>> JS script.
>>
>>>> Please post a link and I'll take a look. What does Firebug say when
>>>> you run it?
>>
>>>> Walter
>>
>>>> On Jun 6, 2009, at 6:48 AM, WLQ wrote:
>>
>>>>> Walter, why ain't the script you've post working. I mean no drag
>>>>> and
>>>>> drop is working now. When I've connected it to my local server.
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" 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/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---