Re: Fix my AJAX Drag and Drop Code
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Fix my AJAX Drag and Drop Code

From: ameshkin <amir.meshkin@gmail.com>
Date: Fri Apr 07 2006 - 18:47:55 CEST

I don't understand whats wrong. I'm very new to PHP and this is
probably something very easy. This is the code.

<?php
  $us = "ameshkin69";
mysql_connect('localhost', 'playlist', 'amir18');
mysql_select_db('playlist');
function parse_data($data)
{
  $containers = explode(":", $data);
  foreach($containers AS $container)
  {
      $container = str_replace(")", "", $container);
      $i = 0;
      $lastly = explode("(", $container);
      $values = explode(",", $lastly[1]);
      foreach($values AS $value)
      {
        if($value == '')
        {
            continue;
        }
        $final[$lastly[0]][] = $value;
        $i ++;
      }
  }
    return $final;
}

function update_db($data_array, $col_check)
{

  foreach($data_array AS $us => $items)
  {
     $i = 0;
     foreach($items AS $item)
     {
       $item = mysql_escape_string($item);
       $us = mysql_escape_string($us);

       mysql_query("UPDATE RecentUploads SET `order` = '$i' WHERE
`User` = '$us'");
       $i ++;
     }
  }
}

// Lets setup Sajax
require_once('Sajax.php');
sajax_init();
// $sajax_debug_mode = 1;

function sajax_update($data)
{
  $data = parse_data($data);
  update_db($data, "AND (`User` = '$us')");
  return 'y';
}

sajax_export("sajax_update");
sajax_handle_client_request();

echo $data;
?>

<style type="text/css">

#box {
    width: 300px;
    float: left;
    margin-left: 5px;
}

body {
        background: #FCFEF4 repeat-x;
        margin: 10px 10px 10px 10px;
        font-family: Arial, Verdana, Helvetica;
        font-size: 76%;
        color: #3F3F3F;
        text-align: left;
        }

h2 {
        color: #7DA721;
        font-weight: normal;
        font-size: 14px;
        margin: 20px 0 0 0;
        }

br {
        clear: left;
}
</style>

<link rel="stylesheet" href="lists.css" type="text/css">
<script language="JavaScript" type="text/javascript"
src="coordinates.js"></script>
<script language="JavaScript" type="text/javascript"
src="drag.js"></script>
<script language="JavaScript" type="text/javascript"
src="dragdrop.js"></script>
<script language="JavaScript" type="text/javascript"><!--
<?php
sajax_show_javascript();
?>
       function confirm(z)
       {
          window.status = 'Playlist Updated';
       }

        function onDrop() {
          var data = DragDrop.serData('g2');
          x_sajax_update(data, confirm);
       }

        window.onload = function() {

                                list = document.getElementById("box");
                DragDrop.makeListContainer( list, 'g2' );
                list.onDragOver = function() { this.style["background"]
= "#EEF"; };
                list.onDragOut = function() {this.style["background"] =
"none"; };
                list.onDragDrop = function() {onDrop(); };

        };

        function getSort()
        {
          order = document.getElementById("order");
          order.value = DragDrop.serData('g1', null);
        }

        function showValue()
        {
          order = document.getElementById("order");
          alert(order.value);
        }
        //-->
</script></head>

<body>

<br />

<ul id="box" class="sortable boxy">
  <?php

$r = mysql_query("SELECT * FROM `RecentUploads` WHERE `User` = '$us'
ORDER BY `UploadDate` ASC");
while($rw = mysql_fetch_array($r))
{
  echo '<li id="'.$rw['FileName'].'">'.$rw['FileName'].'</li>';
}
?>
</ul>

</body></html>
Received on Mon May 1 02:50:40 2006