我现在正在制作一些有趣的网站,但我陷入了困境.
我想执行一个组任务,组中的任何成员都可以启动它.
该集团的所有人都将获得相同的黄金,经验
并分享同样的冷却时间.
我的数据库中有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,@R_404_159@_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,因为它会停止提取.
请帮帮我,因为我真的不知道该怎么做.
你不能像这样嵌套你的execute().
原文链接:https://www.f2er.com/php/130339.html最好的解决方案是将成员列表折叠成一个数组(),关闭连接,然后迭代该数组并更新每个记录.
它应该如下所示:
$select_members_info_stmt->bind_param('ssss',$member_3); $select_members_info_stmt->execute(); $select_members_info_stmt->bind_result($selected_username,$required_experience); $members = array(); while($select_members_info_stmt->fetch()) { // tossing into the array $members[] = array( 'selected_username' =>$selected_username,'level' => $level,'experience' => $experience,'playergold' => $playergold,'required_experience' => $required_experience ); } $select_members_info_stmt->close(); // Now iterate through the array and update the user stats foreach ($members as $m) { if($update_user_stats_stmt = $MysqLi->prepare("UPDATE members SET level = ?,playergold = ? WHERE username = ?")) { // Note that you need to use $m['selected_username'] here. $update_user_stats_stmt->bind_param('iiiiis',$m['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); } }