How can I maintain multiple open queries?

Adam Bajger

I have some php file which needs to use SQL. In that SQL I get multiple results and I use here a while($stmt->fetch()){} loop inside which I need to use another SQL. Can this be accomplished or do I need to store result of the first SQL query and after closing it I can open new SQL query.

Here's code:

function compute_production($local_id, $GameID) {
    global $mysqli, $M, $Q;
    $sql = "SELECT `x`, `y`, `building`, `tier` FROM `GOD_battlefields` WHERE `owner`=? AND `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") as $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 the order is clicked

                        $sql = "SELECT `post_value` FROM `GOD_cache` WHERE `post_name`=? AND `post_value` LIKE ? AND `game_id`=? AND `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 and do nothing
                            // Everything is fine
                            // No action needed
                            // Really


                        }
                        break;
                }
            }
        }



        foreach(tech_get_value($BUILDING, "production") as $r => $value) {
            if ($r == "s" || $r == "io" || $r == "w") {
                // check if cell contains those resources 
                $multiplier = ($Q->resources_in_cell($x, $y)[$r] > $value ? 1 : 0.15);
                $value *= $multiplier; // Multiply gained resources --> if mines/forests/quarries are empty, gained resources are 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 about production costs
        $HTML_battlefield .= "for the cost of: <br />";
        foreach(resources_for_production_gen($x, $y, array($BUILDING, $TIER)) as $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 the $stmt2->bind_param();

Adam Bajger

The answer is: there is no way, how to maintain multiple open queries.

Solution may be using some INNER JOIN, or other JOIN or storing the information from first SQL, close the SQL and then open the next SQL and use stored information.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I maintain a C# process open?

From Dev

How can i order by for multiple queries combination

From Dev

How can I maintain open ssh connection and use it from shell scripts?

From Dev

How can one efficiently maintain a cache of Git repository queries?

From Dev

How can I run multiple raw queries with sequelize in MySql?

From Dev

How can I get an error when running multiple queries with PDO?

From Dev

how i can use multiple select queries in codeigniter?

From Dev

How can I import multiple mysql queries exported as a text with php?

From Java

How can I open multiple files using "with open" in Python?

From Dev

How can I index these queries?

From Dev

How do I open multiple terminals, so I can have multiple shells open?

From Dev

How can I switch to tab view after open multiple files

From Dev

How can I open multiple links using a hotkey?

From Dev

How can I open multiple Snipping Tool instances in Windows (7)?

From Dev

How can I open multiple task managers in Windows 7?

From Dev

How can I open multiple instances of the same document in Evince?

From Dev

How can I open multiple urls to read in c#

From Dev

How can I open multiple links using a hotkey?

From Dev

How can I prevent multiple ajax queries from being run on "prev" button being clicked multiple times

From Dev

How can I prevent multiple ajax queries from being run on "prev" button being clicked multiple times

From Dev

How to maintain code so that it can be used in multiple software?

From Dev

How can I do Multiple Queries (build out a DB) in Node.JS?

From Dev

How can I do Multiple Queries (build out a DB) in Node.JS?

From Dev

How can I maintain stylesheets during Elm development?

From Dev

How can I best maintain integrity between two columns in a table?

From Dev

How can I maintain a pristine/dirty cache in angular $resource?

From Dev

How can I maintain a consistent count of entities with App Engine?

From Dev

How can I gitignore files in a directory structure but maintain the directory structure?

From Dev

How can I maintain referential integrity between two google spreadsheets?

Related Related

  1. 1

    How can I maintain a C# process open?

  2. 2

    How can i order by for multiple queries combination

  3. 3

    How can I maintain open ssh connection and use it from shell scripts?

  4. 4

    How can one efficiently maintain a cache of Git repository queries?

  5. 5

    How can I run multiple raw queries with sequelize in MySql?

  6. 6

    How can I get an error when running multiple queries with PDO?

  7. 7

    how i can use multiple select queries in codeigniter?

  8. 8

    How can I import multiple mysql queries exported as a text with php?

  9. 9

    How can I open multiple files using "with open" in Python?

  10. 10

    How can I index these queries?

  11. 11

    How do I open multiple terminals, so I can have multiple shells open?

  12. 12

    How can I switch to tab view after open multiple files

  13. 13

    How can I open multiple links using a hotkey?

  14. 14

    How can I open multiple Snipping Tool instances in Windows (7)?

  15. 15

    How can I open multiple task managers in Windows 7?

  16. 16

    How can I open multiple instances of the same document in Evince?

  17. 17

    How can I open multiple urls to read in c#

  18. 18

    How can I open multiple links using a hotkey?

  19. 19

    How can I prevent multiple ajax queries from being run on "prev" button being clicked multiple times

  20. 20

    How can I prevent multiple ajax queries from being run on "prev" button being clicked multiple times

  21. 21

    How to maintain code so that it can be used in multiple software?

  22. 22

    How can I do Multiple Queries (build out a DB) in Node.JS?

  23. 23

    How can I do Multiple Queries (build out a DB) in Node.JS?

  24. 24

    How can I maintain stylesheets during Elm development?

  25. 25

    How can I best maintain integrity between two columns in a table?

  26. 26

    How can I maintain a pristine/dirty cache in angular $resource?

  27. 27

    How can I maintain a consistent count of entities with App Engine?

  28. 28

    How can I gitignore files in a directory structure but maintain the directory structure?

  29. 29

    How can I maintain referential integrity between two google spreadsheets?

HotTag

Archive