⚠ 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

how can insert mutiple items



rdroguett

rdroguett
  • profile picture
  • Member

Posted 17 December 2012 - 19:30 PM

Anyone know how I can create a view to enter multiple products to a table manually. In this manner

[PRODUCT NAME] - [AMOUNT] - [PRICE]

According to the model attached image

Bruno Gelman

Bruno Gelman
  • profile picture
  • Member

Posted 22 December 2012 - 14:55 PM

hi! ;)

i have the same problem!

solution??

Thanks!

rdroguett

rdroguett
  • profile picture
  • Member

Posted 24 December 2012 - 06:37 AM

[quote name='Bruno Gelman' timestamp='1356188110' post='4848']
hi! ;)

i have the same problem!

solution??

Thanks!
[/quote]

Please help!

victor

victor
  • profile picture
  • Member

Posted 24 December 2012 - 07:16 AM

can yout explain what you want in more details?

neocastelli

neocastelli
  • profile picture
  • Member

Posted 24 December 2012 - 15:50 PM

[quote name='victor' timestamp='1356333375' post='4852']
can yout explain what you want in more details?
[/quote]

Need some help to make a relationship between products and quantity.
Table1: Products
Columns: id , code, unit, name, size , cost , price
-
Table2: qty_products
Columns: id , product_id , warehouse_id , quantity
the relation between products here is id from products and product_id from qty_products
a simple query for this result is:
SELECT p.id, p.code, p.unit, p.name, p.size, p.cost, p.price, s.quantity, s.warehouse_id FROM products p
INNER JOIN qty_products s ON s.product_id = p.id

this result i need to translate to Grocery CRUD.
function products()
{
$crud = new grocery_CRUD();
$crud->set_table('products');
$crud->set_relation('column','table','column');
$output = $crud->render();
$this->_products($output);
}

victor

victor
  • profile picture
  • Member

Posted 24 December 2012 - 17:14 PM

You can create and use your model.
http://www.grocerycr...ample-included/
And you can find more info in this forum

neocastelli

neocastelli
  • profile picture
  • Member

Posted 24 December 2012 - 17:44 PM

[quote name='victor' timestamp='1356369299' post='4864']
You can create and use your model.
http://www.grocerycr...ample-included/
And you can find more info in this forum
[/quote]

Hello Victor,

I'm New in this, and i really don't know from where start, because you are referring for an function db_update and inser, not for a get :(.
Why is so difficulty to implement INNER JOIN ?

To create a new model is really dificulty to insert again the the controller and explode the correct data.


Thanks,

Dario

neocastelli

neocastelli
  • profile picture
  • Member

Posted 24 December 2012 - 18:10 PM

Good, i make one model and im trying to put on my controller but the result is blank.

Controller:


function productsinstock()
{
$crud = new grocery_CRUD();

$crud->set_model('MY_grocery_Model');

$output = $crud->render();

$this->load->view('commons/header', $meta);
$this->_produse($output);
$this->load->view('commons/footer');
}


Model:
class MY_grocery_Model extends grocery_CRUD_Model{

function getonlyinstock()
{


$sql = 'SELECT p.id, p.code, p.unit, p.name, p.size, p.cost, p.price, s.quantity, s.warehouse_id FROM products p
INNER JOIN warehouses_products s ON s.product_id = p.id';
$query = $this->db->query($sql);
$result = $query->result();
return $result;
}


What is wrong?

Thanks

victor

victor
  • profile picture
  • Member

Posted 24 December 2012 - 18:17 PM

http://www.grocerycr...64-join-tables/ may be this info help you

neocastelli

neocastelli
  • profile picture
  • Member

Posted 24 December 2012 - 20:22 PM

[quote name='victor' timestamp='1356373021' post='4867']
http://www.grocerycr...64-join-tables/ may be this info help you
[/quote]

Thanks Victor,

Solution is below.

DB:


Table1: Products
Columns: id, code, unit, name, size, price

Table2: Qty_products
Columns: id, product_id, location, quantity


the same id are ( id from products and product_id from qty_products).

Controller:


function productsinstock()
{
$crud = new grocery_CRUD();
$crud->set_model('my_grocery_model');
$crud->set_table('products');
$crud->columns('id','code','unit','name','size','price','quantity');
$crud->required_fields('name');
$crud->unset_columns('id');
# I think that this fields is in plus
$crud->fields('id','code','unit','name','size','price','quantity');

$crud->set_subject('Products');

$output = $crud->render();

$this->_produse($output);

}



Model:

function get_list()
{
if($this->table_name === null)
return false;

$select = "{$this->table_name}.*";

$select .= ", qty_products.*";

if(!empty($this->relation))
foreach($this->relation as $relation)
{
list($field_name , $related_table , $related_field_title) = $relation;
$unique_join_name = $this->_unique_join_name($field_name);
$unique_field_name = $this->_unique_field_name($field_name);

if(strstr($related_field_title,'{'))
$select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name";
else
$select .= ", $unique_join_name.$related_field_title as $unique_field_name";

if($this->field_exists($related_field_title))
$select .= ", {$this->table_name}.$related_field_title as '{$this->table_name}.$related_field_title'";
}

$this->db->select($select, false);

$this->db->join('qty_products','qty_products.id = '. $this->table_name . '.id');

$results = $this->db->get($this->table_name)->result();

return $results;
}
}


I hope that this help other people that want to inner join another table. or get another column from different id column name.

Matt

Matt
  • profile picture
  • Member

Posted 15 April 2013 - 21:30 PM

Couldnt quite get the above to work. So slightly tweaked example:

 

    function getJoinedItems()
    {
        $crud = new grocery_CRUD();
        $CI =& get_instance();
        $CI->join = array('user_id','user_profile','user_id');
        $crud->set_model('gc_join_model');
        $crud->set_theme('datatables');
        $crud->set_table('users');
        $crud->set_subject('Users');
        $crud->columns('first_name','last_name','cy');
        $output = $crud->render();
        plugin('grocery_crud',$output);
        return $output->output;
    }

 

class Gc_join_model extends grocery_CRUD_Model  {
 
    function get_list()
    {
        list($field_name, $related_table, $related_field_name) = $this->join;
        $select = "{$this->table_name}.*,$related_table.*";
        
         if(!empty($this->relation))
         {
              foreach($this->relation as $relation)
              {
                   list($field_name , $related_table , $related_field_title) = $relation;
                   $unique_join_name = $this->_unique_join_name($field_name);
                   $unique_field_name = $this->_unique_field_name($field_name);
                  
                    if(strstr($related_field_title,'{'))
                    {
                        $select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\'",$related_field_title))."') as $unique_field_name";
                    }
                    else
                    {  
                        $select .= ", $unique_join_name.$related_field_title as $unique_field_name";
                    }
                      
                   if($this->field_exists($related_field_title))
                   {
                        $select .= ", {$this->table_name}.$related_field_title as '{$this->table_name}.$related_field_title'";
                   }
              }
          }
         
         $this->db->select($select, false);
         $this->db->join("$related_table","$related_table.$related_field_name = {$this->table_name}.$field_name");
         $results = $this->db->get($this->table_name)->result();
         return $results;
    }

}
 

BalaPerdida

BalaPerdida
  • profile picture
  • Member

Posted 15 April 2013 - 21:46 PM

try this. This is running now.

 

 

 

      $crud
                ->set_language('spanish')
                ->set_table('pagos')
                ->unset_edit()
                ->set_subject('Pagos')
                ->set_relation('idhermanos','hermanos','{nombre} {apellidos}')
                ->set_relation('idconceptos_pago','conceptos_pago','descripcion')
                ->columns('idhermanos','idconceptos_pago','fechavalor','fechaapunte','debe','haber')
                ->display_as('idhermanos','Hermanos')
                ->display_as('fechavalor','Fecha valor')
                ->display_as('fechaapunte','Fecha apunte')
                ->add_fields('idhermanos','idconceptos_pago','debe','haber')
                ->required_fields('idhermanos','idconceptos_pago','debe','haber')
                ->set_rules('debe','Debe','trim|decimal|xss_clean')
                ->set_rules('haber','Haber','trim|decimal|xss_clean')
        ;

Sangat Shah

Sangat Shah
  • profile picture
  • Member

Posted 31 July 2018 - 04:54 AM

Try the Dependent dropdown list like: /topic/1087-updated-24112012-dependent-dropdown-library/

 

OR:

 

https://www.grocerycrud.com/examples/set_a_relation_n_n