0

I have a table, myTable, with a single column, myColumn, with a single row.

I want to change the value of myColumn in that first (and only) row.

I tried this, but nothing happens:

$myNewValue = 'foo';
$this->db->update('myColumn', $myNewValue);

What am I doing wrong?

Obviously it must have something to do with not specifying which table, but I don't know how to do that.

1
  • Thanks for the downvote! I found it very insightful and it showed me an entirely new approach to solve this problem from a different perspective. Very constructive and profound feedback. Commented Aug 20, 2020 at 22:10

3 Answers 3

1

Codeigniter's update() needs to follow this syntax:

 update([$table = ''[, $set = NULL[, $where = NULL[, $limit = NULL]]]])
    Parameters:   

        $table (string) – Table name
        $set (array) – An associative array of field/value pairs
        $where (string) – The WHERE clause
        $limit (int) – The LIMIT clause

so besides of adding the correct table name, you'd need to send update data as an array, using this approach:

$myNewValue = array('myColumn'=>'foo');
$this->db->update('myTable', $myNewValue);
Sign up to request clarification or add additional context in comments.

Comments

0

Figured out how to do it:

$this->db->update('myTable', [
    'myColumn' => $myNewValue,
]);

Comments

0

Try this method, it is my favorite format.

$where = array(
       'column_id'=$id
 );
$data = array(
        'column_name'=$data
 );
$this->db->update('table_name', $data,$where);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.