CodeIgniter Forums
Database update problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Database update problem (/thread-28224.html)



Database update problem - El Forum - 03-05-2010

[eluser]JohnnyBravo[/eluser]
Newby question.

I have to make more database operation after each other (insert, update).

Controller:
Code:
$this->store_model->takein_advanced();
$this->store_model->update_products_in_store();

Model:
Code:
function takein()
{
        
$this->firm_id = $this->session->userdata('firm_id');
$this->store_id = $this->session->userdata('store_id');
$this->product_id = $this->uri->segment(3);
$this->product_status = 's';
$this->netto = $this->input->post('netto');
$this->tax = $this->store_model->get_taxdata();

$this->db->insert('products_in_store', $this);
}


function update_products_in_store()
{
        
$this->db->set('products_in_store', 'products_in_store + ' . $qty);
$this->db->where('id', $this->uri->segment(3));
$this->db->update('products', $this);
}

The first query runs well, but the second fails, because it generates something like this:

Code:
UPDATE `products` SET `products_in_store` = 'products_in_store + 12', `firm_id` = '1',
`store_id` = '1', `product_id` = '1', `product_status` = 's', `netto` = '1000',
`tax` = '25' WHERE `id` = '1'

And this table doesn't have fields like product_status, netto, tax, etc...

So, the question is, after I ran the first query, how can I 'delete' the following:
Code:
$this->firm_id, $this->store_id, etc...

Thank you!


Database update problem - El Forum - 03-05-2010

[eluser]danmontgomery[/eluser]
http://php.net/manual/en/function.unset.php