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

  • Home
  • SEARCH
  • 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
  • 0 Views
  • 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

Ask A Question

Stats

  • Questions 505k
  • Answers 505k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I just discovered this myself. Unfortunately, the solution is pretty… May 16, 2026 at 3:26 pm
  • Editorial Team
    Editorial Team added an answer got it. need to use datastr instead of url datatype:… May 16, 2026 at 3:26 pm
  • Editorial Team
    Editorial Team added an answer If you are targeting an OS > 3.2, you can… May 16, 2026 at 3:26 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have two threads, one thread processes a queue and the other thread adds
I have two static methods that I want to use for error handling. One
I have written a web application that interacts with Google calendar (adds/edits/updates events). You
I have two methods that look almost the same, except for the aggregate function
I have two NSMenus with the same NSMenuItems . Only one NSMenuItem in its
I have two classes. One(Person) for getters and setters, and another(People) for compute the
I currently have two models: Campaigns and Videos. Videos belongs to Campaigns and a
The SharePoint web service usergroup.asmx has two methods to add role definitions to a
I have two models Ticket and TicketComment , the TicketComment is a child of
I have a simple app I am messing around with its a basic Master/Details

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.