[eluser]jzmwebdevelopement[/eluser]
Hey Darren,
I have tried what you have said and it seems that if I have more then one sale and update the image it seems to change all data in the other sales to the one that I have chosen to update and not upload the image.
Why?
View:
Code:
<?php if($sales_pages): ?>
<?php foreach($sales_pages as $sale): ?>
<div id ="sales">
<span class"thumbnail"><a >id?>"><img class="thumbnailImg">thumbname?>" alt=""/></a>
<span class="location"><?= $sale->location?></span>
<span class="price"><?= $sale->price?></span>
</span>
</div>
<?php endforeach; ?>
<?php endif; ?>
Controller
Code:
class Editsale extends CI_Controller {
/**
* This document sets the following for the editsale page
*PHP Validation
*Thumbnail and Image Sizes
*Image Locations
*DB Settings
* @author Jess McKenzie
*/
function __construct() {
parent::__construct();
}
function index() {
if(!$this->session->userdata('logged_in'))redirect('admin/home');
$id = $this->uri->segment(4);
# Set Main Page Data
$data['title'] = 'Edit Sale:';
$data['sales_pages'] = $this->sales_model->getSalesPages();
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$data['sale']= $this->sales_model->getSalesContent($id);
#Set The Validation Rules
$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('location', 'Location', 'trim|required|xss_clean');
$this->form_validation->set_rules('bedrooms', 'Bedrooms', 'trim|numeric|required|xss_clean');
$this->form_validation->set_rules('bathrooms', 'Bathrooms', 'trim|numeric|required|xss_clean');
$this->form_validation->set_rules('condition', 'Condition', 'trim|required|xss_clean');
$this->form_validation->set_rules('description', 'Description', 'trim|required|xss_clean');
$this->form_validation->set_rules('price', 'Price', 'trim|required|xss_clean');
if($this->form_validation->run()) #If Valid Run
{
$content = array(
'name' => $this->input->post('name', TRUE),
'location' => $this->input->post('location', TRUE),
'bedrooms' => $this->input->post('bedrooms', TRUE),
'bathrooms' => $this->input->post('bathrooms', TRUE),
'condition' => $this->input->post('condition', TRUE),
'description' => $this->input->post('description', TRUE),
'price' => $this->input->post('price', TRUE)
);
if($_FILES['userfile']['error'] != 4)
{
//Set File Settings
//Set File Settings
$config['upload_path'] = 'includes/uploads/gallery/';
$config['allowed_types'] = 'jpg|png';
$config['remove_spaces'] = TRUE;
$config['overwrite'] = TRUE;
$config['max_size'] = '1024';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
//Continue and resize the image
$data = array('upload_data' => $this->upload->data());
$config['image_library'] = 'GD2';
$config['source_image'] = $this->upload->upload_path.$this->upload->file_name; #resize
$config['new_image'] = 'includes/uploads/gallery/thumbs/';
$config['create_thumb'] = 'TRUE';
$config['thumb_marker'] ='_thumb';
$config['maintain_ratio'] = 'FALSE';
$config['width'] = '175';
$config['height'] = '175';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
if(!$this->upload->do_upload()) //Process the upload function and uploads image
{
$data['message'] = array('imageError' => $this->upload->display_errors()); // Capture any $config errors and output them
}
else
{
$file_info = $this->upload->data(); //Returns an data array
// Append image data to content array in preparation for db update
$content['imagename'] = $file_info['file_name'];
$content['thumbname'] = $file_info['raw_name'].'_thumb'.$file_info['file_ext'];
}
}
// After everything, update DB
if($this->sales_model->updateSale($id, $content))
{
$data['success'] = TRUE;
}
else
{
$data['success'] = FALSE;
}
} # End Form Validation