0

I am using a jQuery plugin to sort the product order. It's working fine on the client site but I also want to update the order in the database. Here is my attempt: HTML:

<ul id="item_list" >
<li id="item_1">Item One</li>
<li id="item_2">Item Two</li>
<li id="item_3">Item Three</li>
<li id="item_4">Item Four</li>
</ul>

jQuery:

$("#item_list").sortable({stop:function(i) {
  $.ajax({
    type: "GET",
    url: "server_items_reorder.php",
    data: $("#item_list").sortable("serialize")
  });
  foreach($_GET['item'] as $key=>$value) {
    mysql_query("UPDATE my_items" SET position = '" . $key . "' WHERE id ='" .         $value . "'");

But I do this, it throws an error: show invalid arguement for foreach. What's wrong?

2 Answers 2

1

Looks like your code might be based on Wil Linssen's post.

Whether it is or not, “invalid argument for foreach” means that $_GET['item'] is empty, or not in the correct format. Try printing it in server_items_reorder.php:

print "$_GET[item]";
Sign up to request clarification or add additional context in comments.

Comments

0

mm.. I think that the name of querystring var is item_list

try this for rename

$('#item_list').sortable('serialize',{key:'item'})

Are you sure that #item_list contains the ids value??

2 Comments

yes...#item_list contains the ids value and i am trying to update the database but its not doing ...here is my html code <li id=item_1>data1</li>
Ok, check alert($("#item_list").sortable("serialize")) before the ajax call and if show something as "item[]=..&item[]=.." etc , the problem is on server_items_reorder.php. print the value of $_GET in server_items_reorder.php foreach($_GET as $k => $v) echo "$k -> $v<br/>"; and check that $_GET['item'] exists, may not arrive to server_items_reorder.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.