[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?>" alt="<?= $image->description?>"> <a >id?>">Delete</a>
<?php endforeach; ?>
<?php endif; ?>
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);
}