⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Get the MAX value in the Form Add and renaming of file both in path and BD



nacoronte
  • profile picture
  • Member

Posted 03 February 2017 - 18:02 PM

Good afternoon, first of all introduce myself to everyone.
 
I have a problem, I need when I register a record, one of the fields take the maximum value of the last record and add 1. I also need the file to upload has the same name as that field in both the file folder (assets/uploads/files) as well as in the database.
 
Example: view CRUD
 
id          registro            nombre              archivo
1           259635            ejemplo01         259635.pdf
2           259636            ejemplo02         259636.pdf
3           259637            ejemplo03         259637.pdf
4           259638            ejemplo04         259638.pdf
5           259639            ejemplo05         259639.pdf

 

view PATH

 

assets/uploads/files/259635.pdf

assets/uploads/files/259636.pdf

assets/uploads/files/259636.pdf

assets/uploads/files/259637.pdf

assets/uploads/files/259638.pdf

assets/uploads/files/259639.pdf

 

 

Thank you very much in advance.

 

 


nacoronte
  • profile picture
  • Member

Posted 13 February 2017 - 10:52 AM

Good morning, he managed to pass on variable value:

 

...

//PASAMOS LA VARIABLE AL CREAR.
$crud->callback_add_field('registro',array($this,'RegistroMaximo'));
....
 
public function RegistroMaximo($value, $primary_key)
{
$this->db->select_max('registro');
$query = $this->db->get('correo');
$result = $query->row();
if (isset($result))
{
$data = $result->registro;
$data += 1;
}
 
return '<input type="text" maxlength="50" value="'.$data.'" name="registro" id="registro" style="width:462px" readonly="readonly">';
}