[eluser]epseix[/eluser]
Help me complete this code...
In my controller's form validation, I want to use the posted "strId" (not unique) to search my database for a row with same "strId", return the result and then perform an update according to the posted "id" (unique).
The methodology is simple: If the same record already exists (according to "strId"), populate new record (according to "id") with the existing record's data...
EVERYTHING is working fine - except I'm wary of how to construct 2 lines of code in my controller - 1. generating the query results and 2. updating the table (specifically, the parameters).
Here is what I have already...
Controller:
Code:
<?php
class Admin extends CI_Controller
{
function form($id)
{
$this->load->library('form_validation');
// ...
$this->template->load_top('header_view', $data);
if ($this->form_validation->run('admin') == FALSE)
{
$this->template->load_side('form_view', $data);
}
else
{
if ($this->input->post('strId') == 'New')
{
// ...
}
else
{
// load model
$this->load->model('Default_model');
$data['duplicates'] = $this->Default_model->get_duplicate(); // call function
// How do I generate the query results?
// I'm presuming the update code is going to be like so...
// $this->db->where('id', $this->input->post('id'));
// $this->db->update('database_table', $duplicates);
$this->template->load_side('admin_view', $data);
}
}
$this->template->load_bottom('footer_view', $data);
}
}
Model:
Code:
<?php
class Default_model extends CI_Model
{
function get_duplicate()
{
$this->db->where('strId', $this->input->post('strId'));
$query = $this->db->get('database_table');
return $query->result_array();
}
}