Add or subtract value from a field in a database with CodeIgniter

0

I'm using CodeIgniter in my application, what I need to do is the following I have in my database a field with stock name, this field is integer value, I need to do the following when I hold a sale it will have to decrease the amount of my sale of that field in PHP would be something like this.

$sql = mysql_query( sprintf( “UPDATE profile_posts SET cliks = cliks + 1 WHERE id = %d” , $id ) )
    or die( mysql_error( ) );

There is some CodeIgniter feature that I can do this or I will have to do a specific SQL for this:

    
asked by anonymous 08.09.2014 / 23:33

1 answer

1

See an example of DOC

$data = array( 'title' => $title , 'name'  => $name );
$this-> db-> where( 'id' , $id );
$this-> db-> update( 'mytable' , $data );

Your query can be written as follows, using set to assign the count

$this->db-> where( 'id' , $id );
$this->db-> set( array( 'cliks' => 'cliks-1' ) );
$this->db-> update( 'profile_posts' );
  

I need to do the following when I make a sale it will have to decrease quantity

Although your query is cliks + 1 , I suppose you have missed the sign.

    
08.09.2014 / 23:49