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"; 
  • one
    Terribly designed code. He would first put in order, and then people show. - Denis Khvorostin


1 answer 1

Pay attention to what $buf and $row - they are the results of different functions.

The mysql_query function mysql_query not return an array , but a resource, so all sorts of $buf['Что-то-там'] will return null .

At the same time, mysql_fetch_array returns just an array , and already in it you can check whether there is a field or not.

And the code is really ugly. I can imagine how you will change the design later. People have come up with template engines for a long time.