我正在实施在线游戏。为了匹配两个用户,我当前正在更新一个带有用户ID的表。一个php程序应无限运行,如果表中有两行以上,它将与它们匹配,并在另一行中输入两个名称,以便用户可以从该表中获取更新。我不太了解php。有实现这个的更好的主意吗?
while(true) {
$cmd = "select * from user_data.request";
$value = $conn->query($cmd);
$rows = $value->num_rows;
if ($rows<2) {
sleep(4);
continue;
}
$m = 1;
while($rows > 1) {
$row1 = $value->fetch_assoc();
$row2 = $value->fetch_assoc();
$cmd = "insert into user_data.match values (\"".$row1['id']."\",\"".$row2['id']."\",".$m.")";
$value = $conn->query($cmd);
$rows = $rows-2;
$cmd = "delete from user_data.request where id=\"".$row1['id']."\" || id=\"".$row2['id']."\"";
}
}
现在,用户将收到更新的表格详细信息。
while(true) {
$cmd = "select * from user_data.match where id1=\"".$u1."\" || id2=\"".$u1."\"";
$value = $conn->query($cmd);
$rows = $value->num_rows;
if ($rows == 0) {
sleep(2);
continue;
}
$row = $value->fetch_assoc();
$user1 = $row['id1'];
$user2 = $row['id2'];
break;
}