2016-03-07 67 views
0

我有一個while循環顯示來自表student的數據和一個額外的列,顯示從employee表id中的下拉選擇,當選中時,更新學生表中的id。我有以下代碼,但顯示它只顯示來自僱主表中的每行1個數據。拿下另一個表值爲下拉

這裏是while循環。任何幫助將不勝感激,提前致謝。

while(($row = mysql_fetch_array($search_result)) && ($row1 =mysql_fetch_array($search_result2))){ 
echo"<form action=manualallocation.php method=post>"; 
echo"<tr>"; 
echo "<td>" . $row['stud_ID']."</td>"; 
echo "<td>" . $row['stud_NAME']."</td>"; 
echo "<td>"."<Select name='ex1'>"."<option value='" .$row1['emp_id'] ."'>" .$row1['emp_id'] ."</option>"."</select>"; 
echo "<td>" . "<input type='char' name='emp_location' value='" .$row1['emp_location'] . "'/> </td>"; 
echo "<td>" . "<input type='char' name='stud_FIELDOFSTUDY' value='" .$row['stud_FIELDOFSTUDY'] . "'/> </td>"; 
echo "<td>" . "<input type='char' name='student_yearCompleted' value='" .$row['student_yearCompleted'] . "'/> </td>"; 
echo "<input type='hidden' name=hidden value=" . $row['stud_ID'] . ">"; 
echo "<td>" . "<input type='submit' name='submit' value=update". "></td>"; 
echo "</tr>"; 
echo "</form>"; 
} 
+0

寫形式的行動=「manualallocation.php」 –

+0

做到了,沒有任何反應..任何其他ALT – Oliver

+0

檢查所有的鏈接我已經給你。 –

回答

1

1)更換&&and。檢查這link文件。

當心優先'and vs &&''|| vs or'之間的差:

<?php 
$bool = true && false; 
var_dump($bool); // false, that's expected 

$bool = true and false; 
var_dump($bool); // true, ouch! 
?> 

由於'和/或' 具有比低優先級的 '=',但 '||/& &' 具有更高

2)在while循環中使用兩個不同的變量$row1$row2。所以第一個變量不能覆蓋第二個變量。

while(($row1 = mysql_fetch_array($search_result)) and ($row2 = mysql_fetch_array($search_result2))) 

爲了您的下拉列表中,選中此鏈接: -

Link1

Link2

警告

mysql_ *在PHP 5.5.0被棄用,它在PHP中被刪除7.0.0。相反,應該使用MySQLi或PDO_MySQL擴展。

希望它會幫助你:)

+0

感謝它的一部分。對於下拉菜單,當我選擇它並按更新時,如何從僱主表中獲取數據並將其更新到學生表中? – Oliver

+0

@Oliver:不客氣:-)我請求你作爲一個新的問題提出這個問題。 –

+0

好的再次感謝 – Oliver

0
while(($row = mysql_fetch_array($search_result)) && ($row = mysql_fetch_array($search_result2))){ 

在這裏,你有第二個語句改寫你的$row變量。你應該使用不同的變量。

while(($row_stud = mysql_fetch_array($search_result)) && ($row_emp = mysql_fetch_array($search_result2))){ 
與EMP數據時

然後用$row_emp

$row_emp['emp_id'] 

,當學生 - $row_stud

$row_stud['stud_ID']  
相關問題