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?
$sql = ("SELECT * FROM dates WHERE dates.from<='".$date."' AND dates.to>='".$date."'");
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
if ($rows >= 1)
{
$row = mysql_fetch_array($result);
if ($rows == 2)
$calendar .= '<td class="calendar-day-booked">';
else
{
if ($row['from'] == $date)
$calendar .= '<td class="calendar-day-from">';
elseif ($row['to'] == $date)
$calendar .= '<td class="calendar-day-to">';
else
$calendar .= '<td class="calendar-day-booked">';
}
}
else
$calendar.= '<td class="calendar-day">';