Php Codeigniter Ajax删除记录并返回可用记录计数

Php Codeigniter Ajax删除记录并返回可用记录计数,php,jquery,mysql,ajax,codeigniter,Php,Jquery,Mysql,Ajax,Codeigniter,下面是我从数据库中删除记录的html、ajax和数据库脚本 HTML 这段代码的基本思想是允许用户只上传5个文件。由于动态ajax删除,我无法获得记录的实时计数。上述代码在删除记录时效果良好。现在我想返回数据库中剩余的行 所以在模型中,我试着用这样的东西 public function delete_gallery_image($id){ $this->db->delete('employer_gallery', array('id' => $id));

下面是我从数据库中删除记录的html、ajax和数据库脚本

HTML

这段代码的基本思想是允许用户只上传5个文件。由于动态ajax删除,我无法获得记录的实时计数。上述代码在删除记录时效果良好。现在我想返回数据库中剩余的行

所以在模型中,我试着用这样的东西

public function delete_gallery_image($id){
        $this->db->delete('employer_gallery', array('id' => $id));
        $sql = " SELECT * FROM (`employer_gallery`) where user_id = $id";
        $query = $this->db->query ( $sql );
        return $query->num_rows ();
    }
如果我得到一个计数,我可以将它分配给变量$maxupload。这样我就可以对文件选择进行一些验证。但是上面的模型不起作用,它给了我一个500的内部服务器错误


有什么办法解决这个问题吗?

@Birla可以使用$id吗?因此,我可以使用where条件,其中user_id=$idi如果您为用户使用会话,则很容易从会话中获取用户id,否则我们需要传递额外的参数。
function delete_gallery_image($id) {
    $this->db->delete ( 'employer_gallery', array (
            'id' => $id 
    ) );

    /* Flush the DB cache */
    $this->db->flush_cache ();

    /* $sql = " SELECT * FROM (`employer_gallery`) where user_id = $id"; */

    $this->db->select ( '*' );
    $this->db->from ( 'employer_gallery' );
    return $rowcount = $query->num_rows ();
}
public function delete_gallery_image($id){
        $this->db->delete('employer_gallery', array('id' => $id));
        return $this->db->affected_rows();
    }
public function delete_gallery_image($id){
        $this->db->delete('employer_gallery', array('id' => $id));
        $sql = " SELECT * FROM (`employer_gallery`) where user_id = $id";
        $query = $this->db->query ( $sql );
        return $query->num_rows ();
    }
function delete_gallery_image($id) {
    $this->db->delete ( 'employer_gallery', array (
            'id' => $id 
    ) );

    /* Flush the DB cache */
    $this->db->flush_cache ();

    /* $sql = " SELECT * FROM (`employer_gallery`) where user_id = $id"; */

    $this->db->select ( '*' );
    $this->db->from ( 'employer_gallery' );
    return $rowcount = $query->num_rows ();
}