I am newbie in CodeIgniter. I created a method that insert record in mysql db table now to make the query stop if record with same name already exists so I wrote:
public function set_project()
{
// If project name already exists?
$query = $this->db->query("SELECT pro_id FROM projects WHERE pro_name = '".$this->input->post('pro_name')."'");
if ( sizeof($query->row_array()) == 0) {
$data = array(
'is_featured' => $this->input->post('is_featured'),
'pro_type' => $this->input->post('pro_type'),
'pro_name' => $this->input->post('pro_name'),
'pro_client' => $this->input->post('pro_client'),
'pro_loc_city' => $this->input->post('pro_loc_city'),
'pro_loc_state' => $this->input->post('pro_loc_state'),
'pro_yr_start' => $this->input->post('pro_yr_start'),
'pro_yr_end' => $this->input->post('pro_yr_end'),
'pro_loc_cur' => $this->input->post('pro_loc_cur'),
'pro_size' => $this->input->post('pro_size'),
'pro_size_cat' => $this->input->post('pro_size_cat'),
'pro_size_units' => $this->input->post('pro_size_units'),
'pro_desc' => $this->input->post('pro_desc')
);
return $this->db->insert('projects', $data);
} else {
return "Already exists";
}
which works fine but who can I show message to my view?
Okay I did it, actually I have to move that check in controller.