开发者

problem with passing variables (php, sql, jquery draggable)

开发者 https://www.devze.com 2023-04-04 03:22 出处:网络
problem with passing variables (php, sql, jquery draggable) Hi, this is my problem: updating sql via jquery draggable.

problem with passing variables (php, sql, jquery draggable)

Hi,

this is my problem: updating sql via jquery draggable.

I have two columns in a开发者_如何学JAVA page populated by sql. drag and drop from one column to another works. My problem, i have problem passing the row id into droppable for sql update. Can you help?

this is the html:

<div class="result_box1">
    <p>&nbsp;</p>
    <div>
        <span>Job Number</span>
        <span>Manager</span>
      <?php do { ?>
        <div class="draggable data_row" >
          <span><?php echo $row_diag['job_number']; ?></span>
          <span><?php echo $row_diag['manager_label']; ?></span>
        </div>
        <?php } while ($row_diag = mysql_fetch_assoc($diag)); ?>
    </div>
  </div>

and here's the javascript:

  $(document).ready(function() {
    $(".draggable").draggable();
    $(".droppable").droppable({
        drop: function() {update_sql(); }
    });
  });


I'm not very clear on what the "problem" is. Assuming you don't know what approach to use to begin with: you could store the row id as a data attribute on the data_row div. So the PHP to output the row would be:

<div class="draggable data_row" data-rowid="<?= $row_diag['rowid'] ?>">
    <span><?php echo $row_diag['job_number']; ?></span>
    <span><?php echo $row_diag['manager_label']; ?></span>
</div>

If you're using jQuery already, you can retrieve the value using the .data() method:

$(".droppable").droppable({
    drop: function(evt, ui) {
        var droppedRowid = ui.draggable.data('rowid');
        update_sql(droppedRowid); 
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号