Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Frist off, lose the SELECT DISTINCT like so:</p> <pre><code>$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 "Top 8" list - if more than 8 A cuts, take them all //Check if there are 8 or less entries in the current event, or if the swim is an A cut </code></pre> <p>This also loses a bit of redundant code, and can speed up the final output (note the commas in the echo statements - the string doesn't need to be concatenated before it is spat out)</p> <pre><code>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> <p>The final problem lies in the second while loop, where the info being put into $condensed_swimmer_info doesn't have the -1 in place, thus is always blank, and $num_of_swimmers never rises to more than 1 over its original value:</p> <pre><code>while ($num_of_swimmers &lt; 80) { foreach ($events as $loe) { $loe = $row['event']; $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; } </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