• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Incrementing db value

#1
[eluser]unknownserv[/eluser]
Is it possible to update a table and increment a value by 1 with active record?
As the update data i'm using
Code:
<?php
$data = array('field' => 'field + 1');
?>
The problem with this is that when CI does the query it does it as SET 'field' = 'field + 1', when it should be SET 'field' = field + 1 for it to work.

Any ideas?
Cheers.

#2
[eluser]sikkle[/eluser]
The point is usually you use auto-incremente but i assume that you already know that.

You better to go with "get the last id number"

$field = $last_id_number + 1;

good luck!

#3
[eluser]Pygon[/eluser]
Not really the point to assume that he's trying to add an "id", especially since he wants to UPDATE a record, and increment it by one, which means he's probably doing something like inserting a new item higher in a weighting row or something similar.

unknownserv:

set('field','field + 1',FALSE); //Might give this a try.

#4
[eluser]unknownserv[/eluser]
Its for a count of users currently on a page, so autoincrement wouldn't work for that.
Thanks for the suggestion, I done a bit more searching and found that $this->db->set() has a 3rd parameter that can be set to false so that it doesn't escape strings.

EDIT: Thanks for the above reply!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.