title: How many sql queries is too many?
body: <p>How many SQL queries is too many? i have the following piece of code which is in a loop that loops between 28-31 times depending on the month selected. It's used to change a css class depending on the date in the database. Everytime the $rows variable is called does it re-run the query? Is this code efficient?</p>
  
  <pre><code>$sql = ("SELECT * FROM dates WHERE dates.from&lt;='".$date."' AND dates.to&gt;='".$date."'");
  $result = mysql_query($sql);
  $rows = mysql_num_rows($result);
  if ($rows &gt;= 1)
  {
      $row = mysql_fetch_array($result);
  
      if ($rows == 2)
          $calendar .= '&lt;td class="calendar-day-booked"&gt;';
      else
      {
          if ($row['from'] == $date)
              $calendar .= '&lt;td class="calendar-day-from"&gt;';
          elseif ($row['to'] == $date)
              $calendar .= '&lt;td class="calendar-day-to"&gt;';
          else        
              $calendar .= '&lt;td class="calendar-day-booked"&gt;';
      }
  }
  else
      $calendar.= '&lt;td class="calendar-day"&gt;';
  </code></pre>