0

I have a box with a couple of entries based upon the ID of a table:

 <ul id="sortable">
 <?php do { ?> <li class="ui-state-default" id="<?php echo $row_Recordset1['entry']; ?>">
     <?php echo $row_Recordset1['PartNo']; ?></li>
 <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

I have defined the sortable jQuery:

 $(function() { 
   $( "#sortable" ).sortable();
 });
 var newp = $("#sortable" ).sortable('toArray');

and what I want to do is simply to pass this array to the next page in the process of recording on the database:

window.location.href = "quotations_build_itemsorder2.php?newp[]="+newp;

I keep getting an empty array.

Help .... please!

NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
Jim Elliott
  • 37
  • 1
  • 5
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://stackoverflow.com/a/14110189/1723893). – NullPoiиteя Feb 04 '13 at 14:41

2 Answers2

0

Since newp is already an array, you wouldn't pass it as newp[], but just newp.

Also, toArray returns an array (presumably), and not a string. You can't concatenate it to a string. The easiest way to handle this would be to convert it to JSON:

"...?newp=" + JSON.stringify(newp)

Then you can use json_decode to get your array on the PHP side.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
0

Take a look at the sortable("serialize") method:

var newp = $("#sortable").sortable( "serialize" )

You will have to rename the id's of your list items according to the format the serialize method requires (see documentation). Like this:

<?php do { ?> <li class="ui-state-default" id="sort_<?php echo $row_Recordset1['entry']; ?>">

EDIT: Also take a look at this jsfiddle example

Paul van Schayck
  • 517
  • 7
  • 10
  • I amended the code as you suggested but when I do a dump_var I get string(15) "[object Object]" – Jim Elliott Feb 04 '13 at 14:58
  • The addition of the {key: "sort"} option was unnecessary. But it still shouldn't show [object Object]. Please have a look at the jsiddle example I provided. – Paul van Schayck Feb 04 '13 at 16:16
  • Got it to work by putting a form on the page and then assigning the hidden variable - var data = $("#thesort").sortable("serialize"); document.getElementById('newp').value = data; Thanks! – Jim Elliott Feb 04 '13 at 17:45