The problem is the following, there is a header and lines, so all the lines are displayed here, but sections and cabinets disappear in the header, although by condition if they exist, then the captions should have inscriptions.
$myCmd = "SELECT * FROM dlpodrazdeleniya, dldoctor, dlSpec, dltime WHERE id='$cat' AND dldoctor.idPodr = dlpodrazdeleniya.idPodr AND dldoctor.SpecID = dlSpec.SpecID AND dldoctor.DoctorID = dltime.DoctorID";$buf = mysql_query($myCmd);echo "<table class='sortable1' id='table'>\n"; echo "<tr align='center'>\n"; if (!empty($buf['Ychastok'])) { echo "<th>Участок</th>\n"; } if (!empty($buf['Cabinet'])) { echo "<th>Кабинет</th>\n"; } echo "<th>ФИО врача</th>\n"; echo "<th>Специалист</th>\n"; echo "</tr>\n"; for($i=1; $i<=mysql_num_rows($buf); $i++) { $row = mysql_fetch_array($buf); echo "<tr align='center'>\n"; if (!empty($row['Ychastok'])) { echo "<td><font color=red>".$row['Ychastok']."</td>\n"; } if (!empty($row['Cabinet'])) { echo "<td><font color=red>".$row['Cabinet']."</td>\n"; } echo "<td><font color=red>".$row['LastName']." ".$row['FirstName']." ".$row['MiddleName']."</td>\n"; echo "<td><font color=red>".$row['SpecName']."</font color></td>\n"; echo "</tr>\n"; } echo "</table>\n";