jquery resizable没有获取/传递对象的正确id

时间:2014-10-29 03:58:12

标签: php jquery

我从mysql调用选定的图像,然后使用下面的jquery可调整大小的脚本。问题是调整大小的对象/图像坐标不是唯一的id保存,而是最后的对象id。如果我特意硬编码它的工作原理。任何人都可以了解我做错了什么,在哪里,怎么做错。谢谢。

<?php

$get_coords = mysqli_query($link, "SELECT * FROM images WHERE appear = 'Yes' AND publication_id = '2'");
while($row = mysqli_fetch_array($get_coords)) {
        $id = $row['image_id'];
        $x = $row['x_pos'];
        $y = $row['y_pos'];
        $h = $row['h_pos'];
        $w = $row['w_pos'];
        $z_depth = $row['z_depth'];
        $name = $row['image_name'];

        echo "<div id='resizable' class='resizable' style='left:".$x."px; top:".$y."px; height:".$h."px; max-width: 1280px; width:".$w."px; z-index:".$z_depth.";'><img src='../article_images/$name'/></div>";

        }

?>

<script type="text/javascript">

var id = '<?php echo $id; ?>';

$('.resizable').resizable({
start : function(event,ui) {
    startW = $(this).outerWidth();
    startH = $(this).outerHeight();
},
stop : function(event,ui) {
    endW = $(this).outerWidth();
    endH = $(this).outerHeight();
    $.post('updatedimensions.php', { endW: endW, endH: endH, id: id }); //If I hard code the id here it works fine
}
});

</script>

updatedimensions.php

<?php

$link = mysqli_connect($db_host, $db_usr, $db_pass) or die("MySQL Error: " . mysqli_error());

mysqli_select_db($link, $db_name) or die("MySQL Error: " . mysqli_error());

$w_coord=$_POST['endW'];
$h_coord=$_POST['endH'];
$id=$_POST['id'];

$sql = "UPDATE images SET h_pos = '$w_coord', w_pos = '$h_coord' WHERE image_id = '$id'";

mysqli_query($link, $sql) or die("Error updating Coords :".mysqli_error());

?>

0 个答案:

没有答案