I have a code which should assign customer to liveagent in round robin manner .
For example i have two table
table -> ChatLiveAgents
Name MobileNumber
A 123456
B 654324
C 099887
and CustomerName is randomly passed using callback URL (working fine)
So what i need is when customer 1 texts it should be assigned to LiveAgent A from ChatLiveAgents table and when customer 2 approached it should be given to LiveAgent B , and Customer 3 to LiveAgent3 and then Customer 4 should be assigned to LiveAgent A.
so i tried but am getting the same value again and again.and it's not passing in round robin style.
below is my code.
$AssignLiveAgent = ""SELECT `Name`, `MobileNumber` , `email` FROM ChatLiveAgents WHERE Name NOT IN (SELECT `LiveAgentName` FROM `AssignAgentstoCustomer`) ORDER BY RAND() LIMIT 1";;
$resultofAssignLiveAgent = $conn->query($AssignLiveAgent);
if ($resultofAssignLiveAgent->num_rows > 0) {
while($row = $resultofAssignLiveAgent->fetch_assoc()) {
$nameofliveagent = $row['Name'];
$sql = "INSERT INTO `AssignAgentstoCustomer`(`LiveAgentName`, `AssignedMobileNumber`, `Date`) VALUES ('".$row['Name']."','".$mobile."','".$currentDayTImeZone."')";
if ($conn->query($sql) === TRUE){$logger->info("Inserted Value Succesfully");}
}
}
Where
$sql = "INSERT INTO `AssignAgentstoCustomer`(`LiveAgentName`, `AssignedMobileNumber`, `Date`) VALUES ('".$row['Name']."','".$mobile."','".$currentDayTImeZone."')";
$row['Name'] is from ChatLiveAgents ,$mobile is from callbackURL , $currentDayTImeZone from PHP Code
Result of query when all three agents are engaged with sigle customer
so as in screenshot my query is not getting looped so that if a fourth customer customs it should allocate the first Liveagent but here it returns null.
Can anyone please help me with this.