Note that there are some explanatory texts on larger screens.

plurals
  1. POExhausting Memory - Tried Fixing Loops, Still Does Not Work
    text
    copied!<p>I'm currently experiencing a memory usage issue - but I cannot figure out where. I've tried replacing some of my foreach loops with for loops or by issuing another query to the DB, but I am still gettting the same error - "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in on line 109". Can anyone provide some insight as to what may be causing the issue? Thank you!</p> <p>Code after @Patrick 's answer:</p> <pre><code> $participating_swimmers = array(); $event_standings = array(); $qualifying_times = array(); $events = array(); $current_event = ''; $select_times_sql = "SELECT event, time, name, year, team, time_standard, date_swum FROM demo_times_table WHERE sex = 'M' AND (time_standard = 'A' OR time_standard = 'B') ORDER BY event, time ASC"; $select_times_query = mysql_query($select_times_sql); //Create array with the current line's swimmer's info while ($swimmer_info = mysql_fetch_assoc($select_times_query)) { if($current_event != $swimmer_info['event']){ $events[] = $current_event = $swimmer_info['event']; } //Create array with the current line's swimmer's info $swimmer_info["time"] = $select_times_row['time']; $swimmer_info["name"] = $select_times_row['name']; $swimmer_info["year"] = $select_times_row['year']; $swimmer_info["team"] = $select_times_row['team']; $swimmer_info["time_standard"] = $select_times_row['time_standard']; $swimmer_info["date_swum"] = $select_times_row['date_swum']; //Create "Top 8" list - if more than 8 A cuts, take them all if (($swimmer_info["time_standard"] == "A") || ($swimmer_info["time_standard"] == "B")) { //Check if there are 8 or less entries in the current event, or if the swim is an A cut if ((count($event_standings[$current_event]) &lt; 8) || ($swimmer_info["time_standard"] == "A")) { //Add swimmer to the list of invites $event_standings[$current_event][] = $swimmer_info; //Keep only the identifying information about the swimmer $condensed_swimmer_info["name"] = $swimmer_info["name"]; $condensed_swimmer_info["year"] = $swimmer_info["year"]; $condensed_swimmer_info["team"] = $swimmer_info["team"]; //Check if swimmers name already appears in list if (!in_array($condensed_swimmer_info, $participating_swimmers)) { //It is a unique user - add them to the list $participating_swimmers[] = $condensed_swimmer_info; } } else { //Add the qualifying time that did not fit into the list to a list of qualifying times $qualifying_times[$current_event][] = $swimmer_info; } } } //Sort each array of times in descending order arsort($event_standings); arsort($qualifying_times); $num_of_swimmers = count($participating_swimmers); while ($num_of_swimmers &lt; 80) { foreach ($events as $loe) { $num_of_qualifying_times = count($qualifying_times[$loe]); $swimmer_info = $qualifying_times[$loe][$num_of_qualifying_times-1]; $event_standings[$loe][] = $swimmer_info; //Keep only the identifying information about the swimmer $condensed_swimmer_info["name"] = $swimmer_info["name"]; $condensed_swimmer_info["year"] = $swimmer_info["year"]; $condensed_swimmer_info["team"] = $swimmer_info["team"]; //Check if swimmers name already appears in list if (!in_array($condensed_swimmer_info, $participating_swimmers)) { //It is a unique user - add them to the list $participating_swimmers[] = $condensed_swimmer_info; } //Remove time from array of qualifying times unset($qualifying_times[$loe][$num_of_qualifying_times-1]); } $new_num_of_swimmers = count($participating_swimmers); if($num_of_swimmers == $new_num_of_swimmers) break; else $num_of_swimmers = $new_num_of_swimmers; } arsort($event_standings); arsort($qualifying_times); foreach($event_standings as $loe =&gt; $event_swimmer) { echo "&lt;h1&gt;",$loe,"&lt;/h1&gt;&lt;br /&gt;"; foreach ($event_swimmer as $es) { echo $es["time"]," ",$es["name"]," ",$es["team"],"&lt;br /&gt;"; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload