• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert ID for an AR Update?

#1
[eluser]codemonkey[/eluser]
See title.

I don't think insert_id() works with $this->db->update()

Am I wrong? Is there another way?

Thanks

#2
[eluser]GrahamDj28[/eluser]
If you update a record, then the ID is already known.
How else would you update the correct record?

And as the name implies, it returns the record ID on an insert. Not on an update

#3
[eluser]codemonkey[/eluser]
[quote author="GrahamDj28" date="1336084875"]If you update a record, then the ID is already known.
How else would you update the correct record?

And as the name implies, it returns the record ID on an insert. Not on an update[/quote]


I see why it wouldn't work.

How can I grab the ID from a loop that checks to see if a value is already in the db?

Example:

Code:
$q = $this
        ->db
        ->where('item_num', $num_to_check)
        ->limit(1)
        ->get('items');

if ( $q->num_rows == 1) {
//then UPDATE
}
//add

#4
[eluser]GrahamDj28[/eluser]
Well, if you want to make sure that a value is unique you can set your DB table column to unique.
Inserting the value for a second time will then fail. So the executed query should return FALSE.

Could you maybe explain what you actually want to do?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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