php - Query inside loop -


I have a function that allows me to get some additional information about a player based on its ID is.

function get_player_details ($ id, $ select = "*") {include ("include / database.php"); $ Result = $ db- & gt; Ready ("SELECT". $ Choose "WHERE` ID from Wp_users`?");); $ Results & gt; BindParam (1, $ id); $ Results & gt; Executed (); $ Player = $ result-> Get (PDO :: FETCH_ASSOC); If (player $ === wrong) {return player $; } And {return player $; }}

Then I am trying to use the function inside a loop:

  $ sql = "select 'to' unban_request 'where 'Player' =: player & amp; solve '=': solve "; $ Ready: Install = $ db-> Ready ($ sql); $ Ready: stable- & gt; Execute (array (': player' = & gt; $ log_info ["id"], ': solution' => 1)); $ Data = $ ready: installation- & gt; Receive all (); If ($ data! == incorrect & amp; amp; and ready; stability-> gt; punctiquity () & gt; {foreach ($ data as $ line) {$ info = get_player_details ( $ Line ["player"], "` username ''); Echo $ information ["user name"]; }}  

Everything works fine, the problem is that the query inside the loop loads the page very slowly, how can I optimize my code?

Use this code.

This will get all player IDs and then run the same query, multiple running running multiple queries to get all records of all players.

  & lt ;? Php function get_player_details ($ id, $ select = "*") {included ("include / database.php"); // implode () 12, 122, 23 $ query = "SELECT" will generate your ID. Select $ "to` wp_users`, where `id` IN (". "," Implode ("," $ all_player_ids). ");" Echo $ query; $ Result = $ db- & gt; Ready ($ query); $ Results & gt; Executed (); $ Player = $ result-> Get (PDO :: FETCH_ASSOC); If (player $ === wrong) {return player $; } And {return player $; }} $ Sql ​​= "SELECT * FROM` unban_requests` where 'player` =: player & amp;` resolve' = 'solution'; $ Ready: Install = $ db-> Ready ($ sql); $ Ready: stable- & gt; Execute (array (': player' = & gt; $ log_info ["id"], ': solution' => 1)); $ Data = $ ready: installation- & gt; Receive all (); If ($ data! == incorrect & amp; $ ready; installation-> gt; punctiquity () & gt; 0) {$ all_player_ids = array (); // Get all player IDs and add array foreach ($ data as $ line) {$ all_player_ids [] = $ line ['player']; } $ All_player_username = get_player_details ($ all_player_ids, "username"); Foreign currency ($ all_player_usernames name $ arr) {echo $ arr ['username']; }}? & Gt;  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -