$crud->callback_before_insert(array($this, 'val_orden'));
----------------------------------------------------------------------------
function val_orden($post_array) { $sql= "SELECT Count(cliente.nombre) FROM contrato INNER JOIN cliente ON contrato.cliente_id = cliente.id WHERE contrato.fecha_fin > now() AND contrato.cliente_id =". $post_array['cliente']; if (mysql_query($sql) > 0) { return $post_array; } else { return false; } }
*******************************************************************************
or
in the model
public function get_empresa($empresa) { $query = $this->db->query("SELECT Count(cliente.nombre) FROM contrato INNER JOIN cliente ON contrato.cliente_id = cliente.id WHERE contrato.fecha_fin > now() AND contrato.cliente_id = $empresa "); return $query->result(); }
$crud->callback_before_insert(array($this, 'val_orden'));
function val_orden($post_array) { if ($this->model->get_empresa($post_array[cliente]) > 0) { return $post_array; } else { return false; } }