Welcome Guest, Not a member yet? Register   Sign In
Image Delete -> Database
#1

[eluser]jzmwebdevelopement[/eluser]
Hello,

I have an issue with trying to delete a row from the database but also incorporate how to unlink the to images from different locations. I cannot get the row to delete or the images to unlink.

Here is my -> db structure cl.ly/292t2t0B001h0Y0C1y1v

My image locations are:

fullpath = /includes/uploads/gallery/
thumbpath = /includes/uploads/gallery/thumbs/

Ideal Situation

What my ideal situation would be is when the delete link is clicked that it will run the function within the index function and then reload the same page with a success message -> I have not successfully been able to get them to work.

My code:

Model:

Code:
function deleteImage($id,$path){
        
        $this->db->delete('images', array('id' => $id));
        
        if($this->db->affected_rows() >= 1) {
            if(unlink($path))
                return TRUE;
            } else{
                return FALSE;
            }
        }

View:

Code:
<?php if(is_array($get_images)): ?>
            
                <?php foreach($get_images as $image): ?>
                <img >thumbpath?&gt;" alt="&lt;?= $image->description?&gt;"> <a >id?&gt;">Delete</a>
                &lt;?php endforeach; ?&gt;
        &lt;?php endif; ?&gt;

Controller:

Code:
function index() {
    if(!$this->session->userdata('logged_in')) {
        redirect('admin/home');
    }
    // Main Page Data
    $page['get_images'] = $this->image_model->getImages();
    $data['cms_pages'] = $this->navigation_model->getCMSPages();
    $data['title'] = 'Delete Gallery Image';
    $data['content'] = $this->load->view('admin/deleteimage',$page,TRUE);

    $this->load->view('admintemplate', $data);

}
#2

[eluser]toopay[/eluser]
If you use a model's function, don't forget to load it first.
#3

[eluser]jzmwebdevelopement[/eluser]
All my models are auto loaded http://cl.ly/2U1F3a2B0s2K0i3k3g13




Theme © iAndrew 2016 - Forum software by © MyBB