我现在只是为了好玩而制作一些网站,但我被困在了一个点上。
我想执行一个小组任务,小组的任何成员都可以开始它。该组的所有人将获得相同数量的金币,经验并共享相同的冷却时间。我的数据库中有 3 个表(我只会显示重要信息)
Members:
username, level, experience, playergold
Levels:
level, required_experience
Groups:
leader, member_1, member_2, member_3, last_quest_started, quest_cooldown
Quests:
success_message, failed_message, chance, minimum_experience, maximum_experience, minimum_gold, maximum_gold, cooldown
我想分组更新last_quest_started和quest_cooldown,我想更新每个成员他/她的等级、经验、playergold
所以在得到组员的每个用户名,任务数据后,计算经验和金币。我用它来更新:
if($select_members_info_stmt = $mysqli->prepare("SELECT members.username, members.level, members.experience, members.playergold, levels.required_experience FROM members INNER JOIN levels ON members.level = levels.level WHERE ((members.username = ?) OR (members.username = ?) OR (members.username = ?) OR(members.username = ?))"))
{
$select_members_info_stmt->bind_param('ssss', $leader, $member_1, $member_2, $member_3);
$select_members_info_stmt->execute();
$select_members_info_stmt->bind_result($selected_username, $level, $experience, $playergold, $required_experience);
while($select_members_info_stmt->fetch())
{
$now = time();
if($update_user_stats_stmt = $mysqli->prepare("UPDATE members SET level = ?, experience = ?, playergold = ? WHERE username = ?"))
{
$update_user_stats_stmt->bind_param('iiiiis', $new_level, $new_experience, $new_gold, $now, $cooldown, $selected_username);
$update_user_stats_stmt->execute();
if($update_user_stats_stmt->affected_rows == 0)
{
echo '<div>Because of a system error it is impossible to perform a task, we apologize for this inconvience. Try again later.</div>';
}
$update_user_stats_stmt->close();
}
else
{
printf("Update user stats error: %s<br />", $mysqli->error);
}
}
$select_members_info_stmt->close();
echo '<div>'.$success_message.'</div><br />';
}
else
{
printf("Select members info error: %s<br />", $mysqli_error);
}
但我不断得到:
更新用户统计错误:命令不同步;您现在无法运行此命令(4 次,这是我的组已满时的大小。)
我只是找不到解决不同步错误的解决方案,因为我无法关闭 $select_members_info_stmt 因为它会停止获取。
请帮帮我,因为我真的不知道该怎么做。