0

I wonder why my jquery UI does not create an array that i can parse to php, this is my list

<ul id="sortable">
              <li id="firstname" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>firstname</li>
              <li id="lastname" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>lastname</li>
              <li id="title" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>title</li>
              <li id="book_title" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>book_title</li>
            </ul>

And here is jQuery

 <script>
$(function() {
    $( "#sortable" ).sortable({
    placeholder: "ui-state-highlight",
    opacity: 0.6,
   update: function(event, ui) {
    var info = $(this).sortable("serialize");
    alert(info);
    $.ajax({
        type: "POST",
        url: "home.php",
        data: info,
        context: document.body,
        success: function(){
        }
  });

}
});
$( "#sortable" ).disableSelection();
});
</script>

thi is the result that alert (info ) gives

 book[]=title

I want to be able to post the array to php so that the user can change the order of the output according to how he changes it in the list. Someone help

edited from here, my home.php file

  <?php 
header("Content-type: text/xml"); 
include_once("config.php");

parse_str($_POST['data'], $order);
echo $order; 

$query = "SELECT    `author`.`surname`,`author`.`firstname`,`publication`.`title`,`book`.`book_title` FROM author, book, publication "; 
$resultID = mysql_query($query, $conn) or die("Data not found."); 

$xml_output = "<?xml version=\"1.0\"?>\n"; 
$xml_output .= "<entries>\n"; 

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ 
$row = mysql_fetch_assoc($resultID); 
$xml_output .= "\t<entry>\n"; 
foreach($order as $col){
    $xml_output = "\t\t<$col>" . $row[$col] . "</$col\n"; 
}    
$xml_output .= "\t</entry>\n"; 
} 
$xml_output .= "</entries>"; 
echo $xml_output;  
?> 

1 Answer 1

3

It's said in sortable.serialize documentation:

...It works by default by looking at the id of each item in the format "setname_number", and it spits out a hash like "setname[]=number&setname[]=number".

But there's only one id in your set of elements that is matching this pattern - it's book_title (setname is 'book', number is 'title'). All the others do not match this pattern, and are just ignored, I suppose.

The easiest approach to this is just to change your ids into this:

post_firstname
post_lastname
post_title
post_booktitle

You can still use the original values, but then you'll have to supply your own expression pattern (and probably key, if the pattern will look like /()(.+)/) as serialize's options. Or you can consider another alternative - toArray method.

Sign up to request clarification or add additional context in comments.

6 Comments

thank you @raina77ow, i changed it now it gives me all of them. Do you know how i can post this results to my home.php file so that i can use the order to otuput my results from mysql database?
The easiest way is just to check all the sent params against some mapping (aliases => columns), then add a stack of the valid ones to ORDER BY clause.
I can say i understood fully what u just wrote but this is what i tried out, am trying to output it in xml but thats not a must, all i need is the user to see the information in the order he wants. i updated the home.php in the original question above, see what i did
i actually meant i can't understand fully what you wrote.
I see, but could you make it into a separate question? It would be not convenient if someone comes to discussion of ORDER BY and such by looking for some jquery-ui sortable related answers.
|

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.