I have a while loop that display data from table student and an extra column that displays a drop down selection from employee table id which when selected, updates the id in student table. I have the following codes but on displaying it shows only 1 data from the employer table each line.
Here is the while loop. Any help would be appreciated, Thanks in advance.
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>";
}
The query:
<?php
$connect=mysql_connect('127.0.0.1', 'root', 'root');
if(!$connect)
{ die("Can't Connect " . mysql_error()); }
mysql_select_db("web",$connect);
if (isset($_POST['submit']))
{
$updatequery = "UPDATE student SET emp_id=emp_id WHERE emp_ID='$_POST[submit]'";
mysql_query($updatequery,$connect);
};
$sql="SELECT * FROM student WHERE emp_id IS NULL";
$search_result=mysql_query($sql,$connect);
$sql2="SELECT * FROM employer ";
$search_result2=mysql_query($sql2,$connect);
?>