Jump to content

How to loop until a certain value is met.


Phpfr3ak

Recommended Posts

Do you mean you want a script that just sits there and waits until a particular db column gets changed?

 

Essentially you'd just make a while(true) loop and inside it query that column and when it changes do something.

 

Not very efficient though.  Perhaps you could explain your situation / goal?

Sorry basically its something along the lines of, Player A buys x amount from player B, the cron runs every :10 on the hour, and essentially sells that resource, resourses have different values, for example at :10 player A sells 100 resourses, 50 of those resources would be in 1 row, and 50 in another, if that makes sense it can vary, hope that explains it somewhat better?

I'm not sure if this is what you were asking for, but I think it will point you in the right direction at least. I am also incredibly new to PHP so I doubt this code is optimal.

 

<?php
$query =
// the query you want to execute once said number is met
$check_query =;
// query used to check current number
$resource_number = mysql_query($check_query);
$resource_goal_number =;
//number to execute query on
$resource_execute = mysql_query($query);

while $resource_number < $resource_goal_number {
 $execute = false;
 if ($execute) {
	 mysql_query($query);
	}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.