Jump to content


how can insert mutiple items

insert multiple items relation

  • Please log in to reply
12 replies to this topic

#1 rdroguett

rdroguett

    Member

  • Members
  • PipPip
  • 18 posts

Posted 17 December 2012 - 07: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

Attached Thumbnails

  • export.png


#2 Bruno Gelman

Bruno Gelman

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 22 December 2012 - 02:55 PM

hi! ;)

i have the same problem!

solution??

Thanks!

#3 rdroguett

rdroguett

    Member

  • Members
  • PipPip
  • 18 posts

Posted 24 December 2012 - 06:37 AM

hi! ;)

i have the same problem!

solution??

Thanks!


Please help!

#4 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 24 December 2012 - 07:16 AM

can yout explain what you want in more details?

#5 neocastelli

neocastelli

    Member

  • Members
  • PipPip
  • 13 posts

Posted 24 December 2012 - 03:50 PM

can yout explain what you want in more details?


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);
}


#6 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 24 December 2012 - 05:14 PM

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

#7 neocastelli

neocastelli

    Member

  • Members
  • PipPip
  • 13 posts

Posted 24 December 2012 - 05:44 PM

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


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

#8 neocastelli

neocastelli

    Member

  • Members
  • PipPip
  • 13 posts

Posted 24 December 2012 - 06: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

#9 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 24 December 2012 - 06:17 PM

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

#10 neocastelli

neocastelli

    Member

  • Members
  • PipPip
  • 13 posts

Posted 24 December 2012 - 08:22 PM

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


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.

#11 Matt

Matt

    Member

  • Members
  • PipPip
  • 14 posts

Posted 15 April 2013 - 09: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;
    }

}
 


#12 BalaPerdida

BalaPerdida

    Newbie

  • Members
  • Pip
  • 7 posts
  • LocationGranada, Spain

Posted 15 April 2013 - 09: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')
        ;

Attached Thumbnails

  • Captura de pantalla de 2013-04-15 23:47:31.png

Edited by BalaPerdida, 15 April 2013 - 10:15 PM.


#13 Sangat Shah

Sangat Shah

    Member

  • Members
  • PipPip
  • 16 posts
  • LocationAhmedabad

Posted 31 July 2018 - 04:54 AM

Try the Dependent dropdown list like: https://www.groceryc...opdown-library/

 

OR:

 

https://www.groceryc..._a_relation_n_n







Also tagged with one or more of these keywords: insert, multiple, items, relation

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users