Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 963531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:41:05+00:00 2026-05-16T01:41:05+00:00

So I have two methods. Method one adds a row to my database. Method

  • 0

So I have two methods. Method one adds a row to my database. Method two selects and updates the latest 10 rows of the table.

If method one adds a new row after method two selects the data but before it updates it will method two update the wrong 10 rows? Will transactions help here or do i need to lock tables?

function one(){
    insert row
}

function two(){
    select latest 10 rows
    update latest 10 rows
}

// EDIT /////////////////////////////////////////////////////////////////////////////

I was reluctant to throw in my actual methods (they are codeIgniter methods) but here they are

function one(){
    insert row
}

function two(){
    $this->db->where('status', '1');
    $this->db->limit(10);
    $query = $this->db->get('rrsf_users');

    $this->db->where('status', '1');
    $this->db->limit(10);
    $this->db->update('rrsf_users', array('status' => '2'));    
}

So it looks like two separate queries hence the “current last 10 rows” problem. Not sure the best fix for this. Lock tables or cycle though each index selected from the query and add this to the where query?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:41:05+00:00Added an answer on May 16, 2026 at 1:41 am

    It is dependend on how you select those 10 rows. If you have a unique index on them and you know which 10 rows to update (and what you update is exactly those 10 rows previously selected) then you do not have a problem. Of course if you write the update statement in a way that you update also the just inserted row you have that problem. Locking as a matter of fact does not help you much here because you only can lock what is already there.

    In short: If you know what you update you have no problem. If you update the “current last 10 rows” you have a problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these two methods on a class that differ only in one method
I have two methods, one called straight after another, which both throw the exact
Quick method description: I have two tables, lets name them table ONE and table
suppose I have a model and a view ,ths view have two method:one is
All -- I have these two methods in one of my classes: public static
I have two methods, one that I use to convert an image to a
Can somebody explain me one thing. I have two methods in my controller :
I have two overloaded methods, one with an optional parameter. void foo(string a) {
I have two ajax calls. Both are sync. Both call methods from one controller.
When I'm testing my simple geometric library, I usually have one or two methods

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.