1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Loop through Updating each row

Discussion in 'PHP' started by neilfurry, Dec 25, 2017.

  1. #1
    hi Mate,

    i posted this question to the wrong section of the forum,..

    How will i use foreach loop to update through thousands of rows in mysql without getting Server problem in one click.

    right now im getting problem "Server Run Away", due to bulk update script because of my loop.

    I want it so that when i update next row it will check if the previous update was successful before going to the next update and make pause for 5 seconds before moving on to the next row to update.

    Thank you
     
    neilfurry, Dec 25, 2017 IP
  2. phpmillion

    phpmillion Member

    Messages:
    145
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    45
    #2
    How many rows are you looking to update at the same time? If there are just a few thousands, you shouldn't experience any issues as long as server is properly optimized.
     
    phpmillion, Dec 26, 2017 IP
  3. neilfurry

    neilfurry Active Member

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #3
    i have 5000 rows, can you give an example of loop where i can see how this being implemented?
     
    neilfurry, Dec 26, 2017 IP
  4. phpmillion

    phpmillion Member

    Messages:
    145
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    45
    #4
    It depends on the exact result you expect.

    You say - it will check if the previous update was successful

    However, "success" might be different in this situation. For example, in one scenario success might be when row was actually updated (I mean, when some new values were entered), in other scenario success might be when MySQL server simply didn't go away and loop can continue (in case some rows have no new data, and don't get updated actually).
     
    phpmillion, Dec 26, 2017 IP