dongpan2788 2018-09-06 10:27
浏览 43

在数据库中存储排序图像顺序的问题

I am having a little problem and I hope that someone can help me out:

So, I am trying to sort images and save the order in the DB, I can set the new order with JS and send it with AJAX to the controller and then to the model, this last one doesn't give any error or so, but for some reason is not saving the order, maybe someone here could see what I am not x), so here is the code (NOTE: I just put the code for sorting images and skipped the main classes just leaving the functions, to make it clear and not showing unnecessary things, however if you need more details, please let me know (= )

Thanks in advance (=.

JS

for(var i = 0; i < $('#desul li').length; i++)
{
   almacenarOrdenId[i] = event.target.children[i].id;
   ordenItem[i] = i+1;
}

$('#btnDesignPortSave').click(function(){

for(var i = 0; i < $('#desul li').length; i++)
{
    var actualizarOrden = new FormData();
    actualizarOrden.append("actualizarOrdenGaleria", almacenarOrdenId[i]);
    actualizarOrden.append("actualizarOrdenItem", ordenItem[i]);

    $.ajax({

        url:"PATH TO AJAX FILE",
        method: "POST",
        data: actualizarOrden,
        cache: false,
        contentType: false,
        processData: false,
        success: function(respuesta)
        {
            $('#desport ul').html(respuesta);

            swal("Order updated", {
                buttons: false,
                timer: 2000,
            }).then(
                function(){
                    window.location = "designPortfolio";
                }
            );
          }
      })//ajax
   }//for

})//Btn

AJAX FILE

public $actualizarOrdenGaleria;
public $actualizarOrdenItem;

public function actualizarDordenAjax()
{

    $datos = array("ordenGaleria" => $this -> actualizarOrdenGaleria,
                    "ordenItem" => $this -> actualizarOrdenItem);

    $respuesta = gestorDgaleriaController::actualizarOrdenController($datos);

    echo $respuesta;

}

///////////////////////////////////////////////

if(isset($POST["actualizarOrdenGaleria"]))
{
   $c = new Ajax();
   $c -> actualizarOrdenGaleria = $_POST["actualizarOrdenGaleria"];
   $c -> actualizarOrdenItem = $_POST["actualizarOrdenItem"];
   $c -> actualizarDordenAjax();

}

PHP

////CONTROLLER

public function actualizarOrdenController($datos)
{
    gestorDgaleriaModel::actualizarOrdenModel($datos,"DB TABLE");
    $respuesta = gestorDgaleriaModel::seleccionarOrdenModel("DB TABLE");

    foreach($respuesta as $row => $item)
    {
        echo'<li id="'.$item["id"].'" class="bloqueDGaleria">
                <i class="fa fa-times delbtn portdesdel" aria-hidden="true" ruta="'.$item["ruta"].'"></i>
                <a data-fancybox="portdes" href="'.substr($item["ruta"],6).'">
                    <img src="'.substr($item["ruta"],6).'" class="handleDImg"/>
                </a>
            </li>';


    }

}

////MODEL

public function actualizarOrdenModel($datos,$tabla)
{
    $stmt = conexion::conectar()->prepare("UPDATE $tabla SET orden = :orden WHERE id = :id");
    $stmt -> bindParam(":orden", $datos["ordenItem"], PDO::PARAM_INT);
    $stmt -> bindParam(":id", $datos["ordenGaleria"], PDO::PARAM_INT);

    if($stmt->execute())
    {
        return "ok";
    }
    else
    {
        return "error";
    }

    $stmt -> close();


}


public function seleccionarOrdenModel($tabla)
{
    $stmt = conexion::conectar()-> prepare("SELECT id, ruta FROM $tabla ORDER BY orden ASC");
    $stmt->execute();
    return $stmt->fecthAll();
    $stmt->close();
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法