多少 SQL 查询太多了?我有以下一段代码,它在一个循环中,根据所选月份在 28-31 次之间循环。它用于根据数据库中的日期更改 css 类。每次调用 $rows 变量时,它会重新运行查询吗?这段代码有效吗?
$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">';