douyinzha5820 2014-10-18 22:34
浏览 58
已采纳

当jquery-file-upload中“position”的DB值等于“id”时,如何插入数据

how do I insert data when the DB value of "position" is equal to "id", in jquery-file-upload, thanks

if (empty($file->error)) {
            $sql = 'INSERT INTO `'.$this->options['db_table']
                .'` (`name`, `size`, `type`, `title`, `description`, `position`)'
                .' VALUES (?, ?, ?, ?, ?, ?)';
            $query = $this->db->prepare($sql);
            $query->bind_param(
                'sisssi',
                $file->name,
                $file->size,
                $file->type,
                $file->title,
                $file->description,
                $file->position
            );
            $query->execute();
            $file->id = $this->db->insert_id;
        }
        return $file;
  • 写回答

1条回答 默认 最新

  • dongtidai6519 2014-10-27 18:03
    关注

    You should do it in 2 steps:

    if (empty($file->error)) {
            $sql = 'INSERT INTO `'.$this->options['db_table']
                .'` (`name`, `size`, `type`, `title`, `description`)'
                .' VALUES (?, ?, ?, ?, ?)';
            $query = $this->db->prepare($sql);
            $query->bind_param(
                $file->name,
                $file->size,
                $file->type,
                $file->title,
                $file->description
            );
            $query->execute();
            $file->id = $this->db->insert_id;
    
            $sql = 'UPDATE `'.$this->options['db_table']
                .'` SET `position` = `id` WHERE `id` = ?';
            $query = $this->db->prepare($sql);
            $query->bind_param(
                $file->id
            );
            $query->execute();
        }
        return $file;
    

    First insert without position, then update the position based on the last inserted id.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效