how can insert mutiple items
- Single Page
Posted 17 December 2012 - 19:30 PM
[PRODUCT NAME] - [AMOUNT] - [PRICE]
According to the model attached image
Posted 22 December 2012 - 14:55 PM
i have the same problem!
solution??
Thanks!
Posted 24 December 2012 - 06:37 AM
hi!
i have the same problem!
solution??
Thanks!
[/quote]
Please help!
Posted 24 December 2012 - 07:16 AM
Posted 24 December 2012 - 15:50 PM
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);
}
Posted 24 December 2012 - 17:14 PM
http://www.grocerycr...ample-included/
And you can find more info in this forum
Posted 24 December 2012 - 17:44 PM
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
Posted 24 December 2012 - 18:10 PM
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
Posted 24 December 2012 - 18:17 PM
Posted 24 December 2012 - 20:22 PM
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.
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; } }
Posted 15 April 2013 - 21:46 PM
try this. This is running now.
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