2016-11-12 85 views
-2

我需要創建一個下拉菜單並在每一行中提交按鈕的表。 下拉菜單包含來自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> 

下面是我使用的表格:

enter image description here

login_details含表ADVISER細節

enter image description here

+1

我沒有看到結尾的''標籤。 –

+1

如果沒有javascript/jquery的相關代碼,請勿垃圾標籤。 –

+0

一些明智的代碼縮進將是一個好主意。它可以幫助我們閱讀代碼,更重要的是,它可以幫助您**調試您的代碼** [快速瀏覽編碼標準](http://www.php-fig.org/psr/psr-2/ )爲了您自己的利益。您可能會被要求在幾周/幾個月內修改此代碼 ,最後您會感謝我。 – RiggsFolly

回答

0

我忘了關的形式,該問題已得到修復。謝謝你們!

相關問題