从和SQL数据库创建一个表,其中包含一个下拉菜单,其中包含来自另一个SQL表的名称列表

时间:2016-11-12 23:54:19

标签: php html mysql

我需要创建一个带有下拉菜单的表,并在每行中提交按钮。 下拉菜单包含SQL表中的顾问列表。当我选择并顾问并按下提交按钮时,当前行中项目的ID以及随后选择的顾问ID或名称必须发送到另一页面。在我的情况下,它被发送到delete.php。

我的代码bellow为表格的每一行显示一个下拉菜单和一个提交按钮,但是当你按下提交按钮时,如果按下位于表格底部的提交按钮,它将只能正常工作,如果我按任何其他似乎不会从下拉菜单中发送信息。

(我知道我的代码看起来很乱,我正在试验,如果有什么不清楚问我,我会澄清。)  非常感谢你!

<!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>

以下是我正在使用的表格:

enter image description here

包含ADVISER详细信息的login_details表

enter image description here

1 个答案:

答案 0 :(得分:0)

我忘了关闭表格,问题已得到修复。谢谢大家!