从和SQL数据库创建表包含一个下拉菜单与另一个SQL表的名称列表
问题描述:
我需要创建一个下拉菜单并在每一行中提交按钮的表。 下拉菜单包含来自SQL表的顾问列表。当我选择和顾问时,我按下提交按钮,当前行中的项目ID以及选定的顾问ID或名称必须发送到另一页面。在我的情况下,它被发送到delete.php。从和SQL数据库创建表包含一个下拉菜单与另一个SQL表的名称列表
我的代码在下表中显示了一个下拉菜单和一个提交按钮,但是当你按下提交按钮时,只有按下位于表底部的提交按钮,它才会正常工作,如果我按任何其他似乎不从下拉菜单发送信息。
(我知道我的代码看起来凌乱,我正在试验如果有什么不清楚的问我,我会澄清。) 非常感谢!
<!DOCTYPE html>
<html>
<body>
<?php
//this is he code for the qeue
// connect to the database udinh sqli
$con = get_sqli();
// get results from database
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
//select whole list of students from walk_in
mysqli_select_db($con,"login");
$sql="SELECT * FROM walk_in";
$result = mysqli_query($con,$sql);
if (!$result) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
mysqli_close($con);
//Table to dispaly qeueu of students
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th><th>Advisor Student wants to see</th><th>P ID</th><th>Select Advisor to notify on send</th><th>Send Student</th><th> </tr>";
echo "<tr>";
//create a table of students by displaying all the data from result and adding a button
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['Advisor'] . "</td>";
echo "<td>" . $row['pid'] . "</td>";
// echo '<form action="delete.php?id2=' . $row['id'] . '" method="post">';
// drop down menu for selecting advisor as a form submission
// used to name each submit button with the id from walk_in
$formId = $row['id'] ;
echo "<td>" ;
//create a form to submit the sleected advisor and the seelcted student to be removed from the queue
echo '<form action="delete.php?id=' . $row['id'] . '" method="post">';
//another query used to retreive the list of advisors to pupulate the drop down menu
//create a drop down menu with advisors resulting from the queue
echo '<select name="formStatus">';
$con = get_sqli();
mysqli_select_db($con,"login");
$sql="SELECT * FROM login_details WHERE level = 0 AND logged = 1";
$result2 = mysqli_query($con,$sql);
if (!$result2) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
//loops through all advisors for drop down menu creation
while ($row2 = mysqli_fetch_array($result2)) {
$id = $row2['id'];
echo '<option value="'.$id.'">'.$id.'</option>';
}
echo'<option selected="selected"></option>';
echo '</select>';
echo '<td><input type="submit" name="formSubmit" value= "'.$formId.'" /><td>';
//echo '<td><input type="submit" name="formSubmit" value= /><td>';
//echo '<td><a href="delete.php?id=' . $row['id'] . '&advisor='. "lol" .'">Send</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";
?>
<p><a href="new.php">Add a new record</a></p>
</body>
</html>
下面是我使用的表格:
login_details含表ADVISER细节
答
我忘了关的形式,该问题已得到修复。谢谢你们!
我没有看到结尾的''标签。 –
如果没有javascript/jquery的相关代码,请勿垃圾标签。 –
一些明智的代码缩进将是一个好主意。它可以帮助我们阅读代码,更重要的是,它可以帮助您**调试您的代码** [快速浏览编码标准](http://www.php-fig.org/psr/psr-2/ )为了您自己的利益。您可能会被要求在几周/几个月内修改此代码 ,最后您会感谢我。 – RiggsFolly