title: select next event from database
body: <p>I am working on a function which selects a list of dates, and highlight the next event.  I have managed to highlight all future events, however I would like to only highlight the nearest future event.  How can this be done? </p>
  
  <pre><code>&lt;?php
  function racesbydate($sql) {
      include 'connect.php';
      $year = $_GET['year'];
      $get = $year.'%';
      $select = $conn-&gt;prepare($sql);
      $select-&gt;bind_param('s', $get);
      $select-&gt;execute();
      $select-&gt;store_result();
      if ($select-&gt;num_rows &gt; 0) {
          echo "&lt;div class='races' id='$year' style='display:block'&gt;
           &lt;table&gt;\n&lt;th colspan='5'&gt;Cycling Season $year &lt;/th&gt;\n
                  &lt;tr id='information'&gt;\n
                      &lt;th id='date'&gt;Date&lt;/th&gt;\n
                      &lt;th id='race'&gt;Race&lt;/th&gt;\n
                      &lt;th id='route'&gt;Route&lt;/th&gt;\n
                      &lt;th id='info'&gt;Entry&lt;/th&gt;\n
                      &lt;th id='rizultz'&gt;Results&lt;/th&gt;";
          $meta = $select-&gt;result_metadata();
          while ($field = $meta-&gt;fetch_field()) {
              $params[] = &amp;$row[$field-&gt;name];            
          }
          call_user_func_array(array($select, 'bind_result'), $params);
          while ($select-&gt;fetch()) {
              $today = date("Y-m-d");
              $date = new DateTime($row['date']);
              $formatted_date = $date-&gt;format('d/m/Y');
              if ($row['date'] &gt; $today) {  
                  if ($row['infoID'] != "0") {
                      echo "&lt;tr class='racedetails' id='nextrace' &gt;\n
                      &lt;td class='dark' id='date'&gt;".$formatted_date."&lt;/td&gt;\n
                      &lt;td class='light' id='race'&gt;".$row["title"]."&lt;/td&gt;\n
                      &lt;td class='dark' id='route'&gt;".$row["route"]."&lt;/td&gt;\n
                      &lt;td class='light' id='info'&gt;&lt;a href='".$row["infoID"]."'&gt;Info&lt;/a&gt;&lt;/td&gt;\n
                      &lt;td class='dark' id='rizults'&gt;N/A&lt;/td&gt;\n&lt;/tr&gt;\n";
                  }
              } else {
                  if (($row['infoID'] != "0") &amp;&amp; ($row['resultID'] !="0" )) {
                      echo "&lt;tr class='racedetails' id='race' &gt;\n
                      &lt;td class='dark' id='date'&gt;".$formatted_date."&lt;/td&gt;\n
                      &lt;td class='light' id='race'&gt;".$row["title"]."&lt;/td&gt;\n
                      &lt;td class='dark' id='route'&gt;".$row["route"]."&lt;/td&gt;\n
                      &lt;td class='light' id='info'&gt;&lt;a href='".$row["infoID"]."'&gt;Info&lt;/a&gt;&lt;/td&gt;\n
                      &lt;td class='dark' id='rizults'&gt;&lt;a href='".$row["resultID"]."'&gt;Results&lt;/a&gt;&lt;/td&gt;\n&lt;/tr&gt;\n";
                  }
              }
  
          }
      }
      echo "&lt;/table&gt;\n&lt;/div&gt;";
      $select-&gt;close();
  }
  </code></pre>
  
  <p><strong>current result</strong></p>
  
  <pre><code>&lt;tr class='racedetails' id='nextrace' &gt;&lt;td class='dark' id='date'&gt;06/01/2016&lt;/td&gt;&lt;/tr&gt;
  &lt;tr class='racedetails' id='nextrace' &gt;&lt;td class='dark' id='date'&gt;08/02/2016&lt;/td&gt;&lt;/tr&gt;
  </code></pre>
  
  <p><strong>goal results</strong></p>
  
  <pre><code>&lt;tr class='racedetails' id='nextrace' &gt;&lt;td class='dark' id='date'&gt;06/01/2016&lt;/td&gt;&lt;/tr&gt;
  &lt;tr class='racedetails' id='race' &gt;&lt;td class='dark' id='date'&gt;08/02/2016&lt;/td&gt;&lt;/tr&gt;
  </code></pre>