[eluser]jzmwebdevelopement[/eluser]
At this present point in time I have some code that does the following:
I can edit and I can add a house sale that uploads/edits one image for this particular house and then during the process a thumbnail is created and then the original file name and the thumbnail name is saved to database fields called **imagename** and **imagethumb**.
(*Note: Add and Edit a separate pages*)
What my idea is:
I will create another page that has the name of the houses fed into a dropdown menu so when one is selected and images are selected they will upload.
What my issue is:
1. I am getting myself confused as to what would be the best way to modify my database to enable this change.
2. How would I modify my php code to handle more then one file (How do I handle multiple images and then pass the image for uploading resizing etc ) What is the best option? - within my given idea?
3. Could I have an example of what I should do so I can work off this.
I have included the model and controller (As an **Example**) of my Add Sale but I will also need to edit a image for the respective sale.
Code:
**Model:**
class Sales_model extends CI_Model
{
function __construct() {
parent::__construct();
}
function getSalesPage($id = NULL) {
$query = $this->db->get_where('sales', array('id' => $id), 1);
if($query->num_rows() == 1) return $query->row();
} # End getSalesPage
function getSalesPages($id = NULL) { // $id does nothing
$query = $this->db->get('sales');
if($query->num_rows() > 0) return $query->result();
} # End getSalesPages
function getSalesContent($id = NULL) {
$this->db->where('id', $id);
$query = $this->db->get('sales', 1);
if($query->num_rows() > 0) {
$row = $query->result_array();
return $row;
}else{
return FALSE;
} # End IF
} # End getSalesContent
function addSale($data = NULL) {
$this->db->insert('sales', $data);
return TRUE;
} # End Add Sale
function updateSale($id, $content) { //Content id from being passed
$this->db->where('id', $id); // selecting the $id to update
$update = $this->db->get('sales'); // What does $update = well it = get the db sales
$row = $update->row_array(); // what does $row mean = well it gets the row as an array
if($update->num_rows() > 0) {
if(isset($content['imagename']) && isset($content['thumbname'])) {
#lets delete the image
unlink("/includes/uploads/gallery/".$row['imagename']);
#lets delete the thumb.
unlink("/includes/uploads/gallery/thumbs/".$row['thumbname']);
}
$this->db->where('id', $id);
if($this->db->update('sales', $content))
{
return TRUE;
}
else
{
return FALSE;
}
} # End IF
} # End Update
function deleteSale($id){
$this->db->where('id', $id);
$q = $this->db->get('sales');
$row = $q->row_array();
if ($q->num_rows() > 0){
//delete from the database
$this->db->where('id', $id);
$this->db->delete('sales');
//lets delete the image
unlink("includes/uploads/sales/".$row['imagename']);
//lets delete the thumb.
unlink("includes/uploads/sales/thumbs/".$row['thumbname']);
}//END if num_rows
}//END function deleteSale($id)
} # End Model