views:

384

answers:

4

Hi all,

I am trying to convert a PHP/JQuery sortable drag and drop script. I want to add JQuery sortable functionality to a site I have that is written in Classic ASP.

Here is a scaled down version of the script:

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.1.custom.min.js"></script>
<script type="text/javascript">
 // When the document is ready set up our sortable with it's inherant function(s)
  $(document).ready(function() {
    $("#test-list").sortable({
      handle : '.handle',
      update : function () {
       var order = $('#test-list').sortable('serialize');
     $("#info").load("process-sorttest.asp?"+order);
     alert('' + order);
      }
    });
});
</script>

<li id="listItem_1"><img src="img/arrow.png" alt="move" width="16" height="16" class="handle" /><strong>Item 1</strong></li>
<li id="listItem_2"><img src="img/arrow.png" alt="move" width="16" height="16" class="handle" /><strong>Item 2</strong></li>

The Jquery sortable side of the script works perfect. My problems accur trying to save the updated data back to the database.

Here is the PHP version of the script that I would like to convert to ASP:

foreach ($_GET['listItem'] as $position => $item) :
    $sql[] = "UPDATE `table` SET `position` = $position WHERE `id` = $item";
endforeach;

print_r ($sql);

This is the closest I can get in classic asp:

For Each Item In Request.QueryString
    Response.write "Processing: " & Request.QueryString("listItem[]") & "<br />"
Next

This gives me the ID's of the menu item I am modifiying however the reason I want to convert this script is because the PHP script reads and prints both the new order of the sort and the ID of the list item. All that my asp prints are the ID of the list items "Processing 1, 2"

Any help would be greatly appreciated..

+3  A: 

The "For Each ... Next" construct in ASP works like this:

For Each <itemvar> In <collectionvar>
    ...
Next

Each iteration of the loop will put one item from collectionvar into the variable itemvar (both being placeholders for actual variables/values). Currently, your loop is accessing Request.QueryString("listItem[]") which is the same no matter what iteration of the loop you're on. Instead, you need to use the "Item" variable you defined in your For Each loop to process different items on each time through the loop.

Amber
Jason
That's a step in the right direction, yes.
Amber
Thanks Dav, your help was much appreciated.
Jason
A: 

Try something like this http://www.me-u.com/php-asp/ its not perfect but could be helpful

Ali
+1  A: 

Not really an answer to your question, but linking sucks in comments:

Your PHP code looks like it suffers from SQL injection vulnerabilities. You might want to read up on that to make sure you don't make the same mistake in ASP.

What it comes down to, is that you shouldn't assume that user input to be safe. You're taking variables straight out of the query string and assuming them to be numbers. In fact, they could be partial SQL statements.

Thorarin
A: 

Have you tried Request.QueryString(Item) instead of Request.QueryString("listItem[]")

The loop For Each Item In Request.QueryString doesn't produce anything for listItem[] and sure as heck doesn't produce anything for "listItem[]"

anschauung