Hi, this might be a pretty confusing problem.
But I’m stuck with some infinite loops :eek:
[PHP]function setStaging($boardpoint,$task) {
$date = date(“dmY”);
$this->getRandomPerson($boardpoint,$task,$n);
return true;
}
//Run the function to get a random person from database
function getRandomPerson($boardpoint,$task,$n) {
$sql_text = “SELECT id, name, $task FROM “.$this->TABLES[‘staff’].” WHERE $task = ‘yes’”;
$data = $this->sql->Select($sql_text);
$i=0;
$len = count($data);
$random_number = rand(1,$len);
$array = array(0 => “holder”);
for ($i=0; $i< $len; $i++) {
array_push($array, $data[$i][‘name’]);
}
$person = $array[$random_number];
$this->addPersonToBackup($boardpoint,$person,$task,$n);
return true;
}
//Built an array with all the people who can do the “staging job”
//Call function to add person to database.
function addPersonToBackup($boardpoint,$person,$task,$n) {
$date = date(“dmY”);
$sql_text = “SELECT id, date FROM “.$this->TABLES[‘backup’].” WHERE date = ‘$date’”;
$data = $this->sql->Select($sql_text);
$i=0;
$len = count($data);
if ($task == “fastpost”){
$holder = $task.$n;
}else{
$holder = $task.$boardpoint;
}
if ($data[$i]['date'] !="") {
$this->sql->Update("UPDATE ".$this->TABLES['backup']." SET $holder = '".$person."' WHERE date = $date");
}else{
$this->sql->Insert("INSERT INTO ".$this->TABLES['backup']." ($holder, date) VALUES ('".$person."','".$date."')");
}
if ($task == “staging”){
$this->stagingChecker($boardpoint,$person,$task,$n);
}
return true;
}
//Have to check to see if the person is already allocated to another job before continuing.
function stagingChecker($boardpoint,$person,$task,$n){
$date = date(“dmY”);
$sql_text = “SELECT id, date, fastpost1, fastpost2, fastpost3 FROM “.$this->TABLES[‘backup’].” WHERE date = ‘$date’”;
$data = $this->sql->Select($sql_text);
$len = count($data);
$i=0;
if ($data[$i][‘fastpost1’] == $person || $data[$i][‘fastpost2’] == $person || $data[$i][‘fastpost3’] == $person) {
$this->getRandomPerson($boardpoint,$task,$n);
}else{
return true;
}
}
//Checks to see if person is set to fastpost. If they aren’t. All is fine, if they are, go back and pick another person.
//People cant do both jobs at once.
[/PHP]
The issue I have is I have more jobs that get checked. As it goes down the list checking, it allocates more and more people. When it gets to the final job for the hour there are still a lot of people going into the array who already have a job to do.
How do I get them out of the array?
Because its randomly picking them, it can pick people who already are on a job. Infinite loop there.
But if it only builds an array with people who aren’t on jobs, then it only has viable people to pick.
Any help would be appreciated.