Welcome Guest, Not a member yet? Register   Sign In
Updating numbers model,help
#1

[eluser]phpserver[/eluser]
I am kind of stuck.I want to update a record in a database.That record is a digit,for instance a customer has $200 left in his/her account.In the form,he/she indicates he want to deposit $100.Here is my code

Code:
$data = array
                    (
                        'ebenki_balance' => $ebenki_balance + $this->input->post('ebw')
                                  
                    );

This dont seem to work,anybody with some code that could enable me update such a record.Thank you.
#2

[eluser]bigtony[/eluser]
All your posted code does is assign a value to an array element. Arrays are not databases, so you might want to look at [url="http://ellislab.com/codeigniter/user-guide/database/index.html"]The Database Class[/url]
#3

[eluser]phpserver[/eluser]
[quote author="bigtony" date="1254852553"]All your posted code does is assign a value to an array element. Arrays are not databases, so you might want to look at [url="http://ellislab.com/codeigniter/user-guide/database/index.html"]The Database Class[/url][/quote]

Code:
$data = array(
               'title' => $title,
               'name' => $name,
               'date' => $date
            );

$this->db->where('id', $id);
$this->db->update('mytable', $data);

The user guide tells you this.I want to actually add the existing value in the database to the new posted value.
#4

[eluser]phpserver[/eluser]
What i mean is supposing you are to edit some kind of text,you just type in new data,and you have performed an update,in this case i want ot increment the existing value(say $200) with a post value of $100,how do i do it?
#5

[eluser]davidbehler[/eluser]
Try this
Code:
$this->db->set('ebenki_balance', 'ebenki_balance + '.$this->input->post('ebw'), FALSE);
$this->db->where('id', $id') // or whatever else you do here
$this->db->update('table_name');
#6

[eluser]phpserver[/eluser]
Is this allowed?

Code:
$data = array(
               'balance' => set $balance = $balance + $this->input->post('ebw') ,
               'name' => $name,
               'date' => $date
            );

$this->db->where('id', $id);
$this->db->update('mytable', $data);
#7

[eluser]Zack Kitzmiller[/eluser]
No, that is not allowed. You don't even have quote around anything.

Use can use pure SQL if you prefer and use $this->db->query();




Theme © iAndrew 2016 - Forum software by © MyBB