Вы можете добавить, прежде чем перебирать, записи новой строки с соответствующими заголовками столбцов. Как правило, вы можете использовать тег th
, хотя он может быть стандартным тегом td
, если вы пожелаете.
<?php
$numeroOption= $_POST['numero'];
$roomtype= $_POST['roomtype'];
$selectOption = $_POST['parkname'];
$query = "SELECT * FROM `ROOMS` WHERE `Capacity` < '$numeroOption' AND `Park` LIKE '$selectOption%' AND `dataProjector` LIKE '$proj_check%' AND `Whiteboard` LIKE '$white_check%' AND `OHP` LIKE '$ohp_check%' AND `WheelchairAccess` LIKE '$wheel_check%' AND `lectureCapture` LIKE '$cap_check%' AND `Style` LIKE '$roomtype%'";
$result = mysql_query($query);
if ($result == FALSE) die ("could not execute statement $query<br />");
echo "<form action='' method='post'>";
echo "<table>
<tr>
<th scope='col'>Room Code</th>
<th scope='col'>Style</th>
<th scope='col'>Projector</th>
<th scope='col'>Whiteboard</th>
<th scope='col'>OHP</th>
<th scope='col'>Wheelchair Access</th>
<th scope='col'>Lecture Capture</th>
<th scope='col'> </th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>" . $row['roomCode'] . "</td>";
echo "<td>" . $row['Style'] . "</td><td>" . $row['dataProjector'] . "</td>";
echo "<td>" . $row['Whiteboard'] . "</td><td>" . $row['OHP'] . "</td>";
echo "<td>" . $row['wheelchairAccess'] . "</td>";
echo "<td>" . $row['lectureCapture'] . "</td>";
echo "<td><input type='radio' name='radioSelect' value= '". $row['roomCode']."'></td></tr>";
}
echo "<input type='submit' name='ttroom' id='ttroom' name='ttroom'>";
echo "</tr>";
echo "</table>";
echo "</form>";
?>
Что-то я не заметил сразу, является отсутствие закрытия tr
тег внутри цикла - есть только один закрывание tr
тег, и это вне цикла! Чтобы добавить заголовки столбцов динамически, основываясь на фактических имен полей (что я изначально думал, что ты хотел сделать, вы можете использовать такой подход, как это: -
<?php
$numeroOption= $_POST['numero'];
$roomtype= $_POST['roomtype'];
$selectOption = $_POST['parkname'];
$query = "SELECT * FROM `ROOMS` WHERE `Capacity` < '$numeroOption' AND `Park` LIKE '$selectOption%' AND `dataProjector` LIKE '$proj_check%' AND `Whiteboard` LIKE '$white_check%' AND `OHP` LIKE '$ohp_check%' AND `WheelchairAccess` LIKE '$wheel_check%' AND `lectureCapture` LIKE '$cap_check%' AND `Style` LIKE '$roomtype%'";
$result = mysql_query($query);
if ($result == FALSE) die ("could not execute statement $query<br />");
/* an array to store column names */
$colheaders=array();
/* find how many fields in each row there are */
$iCols=mysql_num_fields($result);
/* Get the column names */
for($i=0; $i < $iCols; $i++) $colheaders[]=mysql_field_name($result, $i);
/* Add an item for the radio buttons */
$colheaders[]='Options';
/* ensure all of recordset is available to iterate through after getting field names*/
mysql_data_seek($result, 0);
echo "<form action='' method='post'>";
echo "<table>
<tr>";
foreach($colheaders as $colname) echo "<th scope='col'>{$colname}</th>";
echo "
</tr>";
while($row = mysql_fetch_array($result)){
echo "
<tr>
<td>" . $row['roomCode'] . "</td>
<td>" . $row['Style'] . "</td>
<td>" . $row['dataProjector'] . "</td>
<td>" . $row['Whiteboard'] . "</td>
<td>" . $row['OHP'] . "</td>
<td>" . $row['wheelchairAccess'] . "</td>
<td>" . $row['lectureCapture'] . "</td>
<td><input type='radio' name='radioSelect' value= '". $row['roomCode']."'></td>
</tr>";
}
echo "
<tr>
<td colspan='".count($colheaders)."'><input type='submit' name='ttroom' id='ttroom' name='ttroom'></td>
</tr>
</table>
</form>";
?>
есть бродячий/запасной тег 'form' – RamRaider