Jump to content

Recommended Posts

i want to kno if im going about this corectly i want to update a some database values and delete some values apon a certain time  and this cod sits on a cron job runiing every5 mins tell me if ive done anything wrong?

<?

// grab all clutches and check if they are due yet 
$con = mysql_connect('localhost','xxxuser','xxxpass');
mysql_select_db('ab6691_snakesbay_game',$con);
$all = "SELECT * FROM cluth";
$clu =  mysql_query($all)or die(mysql_error());
$all = mysql_fetch_assoc($clu)or die(mysql_error());
// check if they hatched yet
while($all = mysql_fetch_assoc($clu)){
	$now = strtotime(date("Y-m-d h:i:s"));
	$due = strtotime($all['due_date']);
	$id = $all['id'];
	echo "clutch id : $id";
	if($now >= $due){	
	$all_s = "SELECT * FROM snakes WHERE `clutch_id` = '$id' ";	
	$al_s = mysql_query($all_s);

		while($snake = mysql_fetch_assoc($al_s)){
				// change for everyone!
				$sid = $snake['snake_id'];
				$sql = "UPDATE `ab6691_snakesbay_game`.`snakes` SET `staus` = 'nu' WHERE `snakes`.`snake_id` = '$sid'";
				mysql_query($sql)or die(mysql_error());
				echo "Snakes Have been Updated...<br>";

		} 
	$sql = "DELETE  FROM `ab6691_snakesbay_game`.`cluth` WHERE `clutch_id` = '$id' ";
				mysql_query($sql)or die(mysql_error());	
	}else{
		echo "the clutch woth the id <u>$id</u> Does not need to be updated ";

	}
	// delete that clutch
		$del = "DELETE FROM `ab6691_snakesbay_game`.`cluth` WHERE `cluth`.`id` = $id";	
		mysql_query($del)or die(mysql_error());			
}
echo "</table>";

?>

all of the above becuase i was just getting an error before with the die but i removed it and it works fine now , i figured it out own my own with some debugging but is this a good way of going about this because im feeling like my hosting sucks because its takes forever for theese scripts to get executed.....

all of the above becuase i was just getting an error before with the die but i removed it and it works fine now , i figured it out own my own with some debugging but is this a good way of going about this because im feeling like my hosting sucks because its takes forever for theese scripts to get executed.....

 

Because you are running queries in loop, within loops, etc. That is terribly inefficient. You need to learn how to do JOINs. But, based upon what it looks like you are doing (and a previous thread of yours) I don't think you even need to be running these updates. You can determine what you need by JOINing the tables. I explained all this in the other thread.

 

Also, you are skipping the very first record every time you run that script.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.