Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    limiting number of rows operated on!

    Hey everyone,

    I have a question/problem. I'm trying to select rows and update them, but there are too many rows which causes a timeout on my server. Is it possible to use a loop or something so that only 50 rows are done at once? I know there's this limit 50 thing, but i dont get how to make it so that the script loops until everything is done. I'm using a while loop..

    I have mysql_num_rows down already, but i need to be able to do 50 each until the entire number of rows are sorted, and i think i'll need to sleep(); the script for 1-2 seconds in between each 50 rows.

    Please help me!

    Thanks!

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Posts
    456
    Thanks
    0
    Thanked 20 Times in 20 Posts
    are you trying to reset column info to a default in your data table?
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Can you post the code you are using. There is probably a way to change it so that it will run a lot more efficiently.

    5000 rows to be updated in the table would still be considered to be a very small number that would take almost no time at all if done correctly.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    New Coder
    Join Date
    Dec 2011
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yep.

    I'm essentially changing user information based on certain requirements, and if the user meets them.

    Code:
    	global $db, $db_table_prefix, $loggedInUser;
    	// Base Query, GO.
    	$sql = "SELECT * FROM Users";
    	$result = mysql_query($sql);
    	$tot = mysql_num_rows($result);
    	while ($row = mysql_fetch_assoc($result))
    	{
    		
    		$userId = $row['User_ID']; // Define user ID
    		$group = $row['Group_ID']; // Define current group ID
    		$elapsedTime = ($row['LastSignIn'] - $row['SignUpDate']) / (60*60*24); // Find elapsed # of days user has been a member.
    		$totalEarnings = $loggedInUser->User('3',$userId); // total earnings
    		$totalComplete = getCompleted('16',$userId); // total completed stuff
    		
    		// Conditionals
    		if($totalEarnings > 5 && $totalComplete >= 10 && $elapsedTime >= 14)
    		{
    			if(changeTier($userId, '4') == true)
    			{
    				echo ''.$userId.' has been changed to tier 4.';
    			}
    		}
    		elseif($totalEarnings > 1 && $totalComplete >= 5 && $elapsedTime >= 5)
    		{
    			if(changeTier($userId, '3') == true)
    			{
    				echo ''.$userId.' has been changed to tier 3.';
    			}
    		}
    		elseif($totalEarnings > 0.05 && $totalComplete >= 1 && $elapsedTime >= 1)
    		{
    			if(changeTier($userId, '2') == true)
    			{
    				echo ''.$userId.' has been changed to tier 2.';
    			}
    		}
    		echo ''.$userId.' has been edited.';
    	}


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •