php - How can I maintain multiple open queries? -
i have php file needs use sql. in sql multiple results , use here while($stmt->fetch()){}
loop inside need use sql. can accomplished or need store result of first sql query , after closing can open new sql query.
here's code:
function compute_production($local_id, $gameid) { global $mysqli, $m, $q; $sql = "select `x`, `y`, `building`, `tier` `god_battlefields` `owner`=? , `game_id`=?"; $stmt = $mysqli->prepare($sql); $stmt->bind_param("ii", $local_id, $gameid); $stmt->execute(); $stmt->bind_result($x, $y, $building, $tier); while($stmt->fetch()) { $ab_triggered = array(); foreach(tech_get_value($building, "abilities") $ability_name => $required_tier) { if ($tier >= $required_tier) { switch($ability_name) { case "auto_production": $ab_triggered[$ability_name] = "true"; break; case "toggle_production": case "double_production": // check if order clicked $sql = "select `post_value` `god_cache` `post_name`=? , `post_value` ? , `game_id`=? , `round`=?"; $ab_triggered[$ability_name] = "false"; $post_name = 'abilityorder_'.$x.'_'.$y; $stmt2 = $mysqli->prepare($sql); $stmt2->bind_param("ssii", $post_name, $ability_name, $gameid, $q->game_round); $stmt2->execute(); $stmt2->bind_result($abilityorder); if ($stmt2->fetch()) { $stmt2->close(); $ab_triggered[$ability_name] = "true"; } else { // keep calm , nothing // fine // no action needed // } break; } } } foreach(tech_get_value($building, "production") $r => $value) { if ($r == "s" || $r == "io" || $r == "w") { // check if cell contains resources $multiplier = ($q->resources_in_cell($x, $y)[$r] > $value ? 1 : 0.15); $value *= $multiplier; // multiply gained resources --> if mines/forests/quarries empty, gained resources decreased } $value *= tech_get_value($building, "productionm", $r) ** ($tier - 1); if ($ab_triggered["toggle_production"] == "true" || $ab_triggered["auto_production"] == "true") { $res_per_turn[$r] += $value; } } // information production costs $html_battlefield .= "for cost of: <br />"; foreach(resources_for_production_gen($x, $y, array($building, $tier)) $resource => $cost) { if ($ab_triggered["toggle_production"] == "true" || $ab_triggered["auto_production"] == "true") { $res_per_turn[array_search($resource, $dictionary_resource)] -= $cost; } } } return $res_per_turn; }
keeps throwing errors on $stmt2->bind_param();
the answer is: there no way, how maintain multiple open queries.
solution may using inner join
, or other join
or storing information first sql, close sql , open next sql , use stored information.
Comments
Post a Comment