⚠ 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

Calculation between 2 tables



Prosspitty
  • profile picture
  • Member

Posted 01 March 2017 - 15:44 PM

Hi everybody..

 

This is my firts time using GroceryCrud, and I believe it's a great tool, I have the followin question;

 

In my proyect I have 2 tables

 

Table: paises

Fields: id_paises, nombre...., ultimo_no_cliente

 

Table: clientes

Fields: id_clientes, id_paises, numero_cuenta, nombre,....... etc,

 

I have a crud on the "clientes" table, and I need to take the field from "paises.ultimo_no_cliente" to save that number + 1 into the table "clientes.numero_cuenta".

 

Also I need to update "paises_ultimo_no_cliente + 1" in the table paises.

 

Can you guys help me with this question ???

 

Regards, from Guayaquil, Ecuador - South America


xheradon
  • profile picture
  • Member

Posted 01 March 2017 - 16:51 PM

Necesitas utilizar callbacks. Échale un ojo a la API. http://www.grocerycrud.com/documentation/options_functions


Prosspitty
  • profile picture
  • Member

Posted 01 March 2017 - 17:34 PM

Yes I use callbak_before_insert from the Clientes, but I do not know how to reference the table "paises" in order to get the field "ultimo_numero_cliente"


xheradon
  • profile picture
  • Member

Posted 02 March 2017 - 08:31 AM

En el callback tienes que hacer una búsqueda en la base de datos en la tabla de la que quieras coger el dato y luego meterlo en la otra tabla que quieres. Es que no entiendo muy bien lo que quieres hacer.


robertlim
  • profile picture
  • Member

Posted 27 August 2017 - 18:34 PM

Ola! I am also new to grocery_CRUD...did you manage to get this working? I am interested in doing the same. I have 2 tables, I can bring up the information for display.. now, I want to multiply the total_weight by the cpk1,  cpk2, cpk3 and display the result in a table (or insert them into the cpk columns). Any help will be much grateful :-) muchos gracias/Thanks

 

public function orders()
{
$crud = new grocery_CRUD();
$crud->set_table('orders');
$crud->set_subject('Orders');
$crud->columns('job_number','total_quantity','total_weight','total_volume');
$crud->fields('job_number','total_quantity','total_weight','total_volume');
$crud->unset_add();
$crud->unset_delete();
 
$output = $crud->render();
 
$this->_example_output($output);
}
 
public function rate_exsyd()
{
$crud = new grocery_CRUD();
$crud->set_table('3pnrate_exsyd');
$crud->set_subject('Rates Ex-SYD');
$crud->columns('zone_loc','zone_id','basic_rate','fuel_charges','cubic_factor','cpk1','cpk2','cpk3','S1','S2','S3','SATC1','SATC3','SATC5','C1');
$crud->fields('zone_loc','zone_id','basic_rate','fuel_charges','cubic_factor','cpk1','cpk2','cpk3','S1','S2','S3','SATC1','SATC3','SATC5','C1');
$crud->unset_add();
$crud->unset_delete();
 
$output = $crud->render();
 
$this->_example_output($output);
}