Php 表中的下拉列表
为什么我的下拉列表在表格中被分隔为不同的列。示例我希望在下拉列表中显示3个选项。这些是我数据库中的数据 例如:Php 表中的下拉列表,php,html-table,Php,Html Table,为什么我的下拉列表在表格中被分隔为不同的列。示例我希望在下拉列表中显示3个选项。这些是我数据库中的数据 例如:公司a、公司b将显示在下拉列表中 现在,下拉列表中只有一个选项(公司a),而(公司b)显示在表格的下一行,而不是在单个下拉列表中一起显示 <? $result = mysqli_query($con,"SELECT admin_no, name, GPA, gender, job_details.job_title, job_details.no_of_vacancy FROM
公司a、公司b
将显示在下拉列表中
现在,下拉列表中只有一个选项(公司a)
,而(公司b)
显示在表格的下一行,而不是在单个下拉列表中一起显示
<?
$result = mysqli_query($con,"SELECT admin_no, name, GPA, gender, job_details.job_title, job_details.no_of_vacancy FROM student_details, job_details ORDER BY `GPA` DESC ");
$result2 = mysqli_query($con, "SELECT job_title FROM job_details;");
$row2 = mysqli_fetch_assoc($result2);
while($row = mysqli_fetch_assoc($result))
{
while ($row2 = mysqli_fetch_array($result2))
{
echo "<tr>";
echo "<td bgColor=white>" . $row['admin_no'] . "</td>";
echo "<td bgColor=white>" . $row['name'] . "</td>";
echo "<td bgColor=white>" . $row['GPA'] . "</td>";
echo "<td bgColor=white>" . $row['gender'] . "</td>";
echo "<td><select name='ddl' onclick='if(this.value != '') { myform.submit(); }'><option value='". $row2['job_title'] ."'> ". $row2['job_title'] ."</option></td>";
echo "</tr>";
}
}
echo "</table>";
?>
</form>
试试这个:
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td bgColor=white>" . $row['admin_no'] . "</td>";
echo "<td bgColor=white>" . $row['name'] . "</td>";
echo "<td bgColor=white>" . $row['GPA'] . "</td>";
echo "<td bgColor=white>" . $row['gender'] . "</td>";
echo "<td><select name='ddl' onclick='if(this.value != '') { myform.submit(); }'>";
while ($row2 = mysqli_fetch_array($result2))
{
echo "<option value='". $row2['job_title'] ."'> ". $row2['job_title'] ."</option>";
}
echo "</select></td>";
echo "</tr>";
}
while($row=mysqli\u fetch\u assoc($result))
{
回声“;
回显“$行[“管理员编号]”;
回显“$row['name']”;
回显“$行['GPA']”;
回显“$row['gender']”;
回声“;
while($row2=mysqli\u fetch\u数组($result2))
{
回显“$row2['job_title']”;
}
回声“;
回声“;
}
试试这个,您没有关闭
标记,我已经重写了代码,即将
标记生成移到表生成部分上方。这样可以避免不必要的循环
<?php
$result = mysqli_query($con,"SELECT admin_no, name, GPA, gender, job_details.job_title, job_details.no_of_vacancy FROM student_details, job_details ORDER BY `GPA` DESC ");
$result2 = mysqli_query($con, "SELECT job_title FROM job_details");
$row2 = mysqli_fetch_assoc($result2);
/*options sections start*/
$options= '';
while ($row2 = mysqli_fetch_array($result2))
{
$options .='<option value="'. $row2['job_title'] .'"> '. $row2['job_title'] .'</option>';
}
/*options sections end*/
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td bgColor=white>" . $row['admin_no'] . "</td>";
echo "<td bgColor=white>" . $row['name'] . "</td>";
echo "<td bgColor=white>" . $row['GPA'] . "</td>";
echo "<td bgColor=white>" . $row['gender'] . "</td>";
echo "<td><select name='ddl' onclick='if(this.value != '') { myform.submit(); }'>".$options."</select></td>";
echo "</tr>";
}
echo "</table>";
?>