Forum Moderators: coopster

Message Too Old, No Replies

updating a table based on what is selected in a dynamic drop down menu

         

dainstructor

4:06 pm on Jan 2, 2007 (gmt 0)

10+ Year Member



As I am fairly new to PHP, I am getting caught up trying to update my table. I am running the query:

$query_getAssignment = "SELECT empNo, projectID, period1, period2, period3, period4, period5, period6, period7, period8, period9, period10, period11, period12, projects.projectName FROM assignments LEFT JOIN projects USING (projectID) WHERE assignments.empNo =".$row_employeeList['EmpNo']. " ORDER BY assignments.projectID";

This properly grabs all of the information and repeats it throughout the table for the employee specified by $row_employeeList['EmpNo']. However it only works for the very first employee in the list. i.e. If I remove the first person in the list, it would display the correct information for person 2 (who is now number 1).

I would like to be able to select any employee from the dynamic drop down list and update the table based on that employee's information.

Thanks in advance for the help

eelixduppy

4:09 pm on Jan 2, 2007 (gmt 0)



Where are you getting
$row_employeeList['EmpNo']
from? I think this is where your problems lies...

dainstructor

4:16 pm on Jan 2, 2007 (gmt 0)

10+ Year Member



I borrowed the variable from the section of the code I believe pertained to the drop down menu.

<select name="employeeName" id="employeeName">
<?php
do {
?>
<option value="<?php echo $row_employeeList['EmpNo']?>"<?php if (!(strcmp($row_employeeList['EmpNo'], $row_employeeList['name']))) {echo "selected=\"selected\"";}?>><?php echo $row_employeeList['name']?></option>
<?php
} while ($row_employeeList = mysql_fetch_assoc($employeeList));
$rows = mysql_num_rows($employeeList);
if($rows > 0) {
mysql_data_seek($employeeList, 0);
$row_employeeList = mysql_fetch_assoc($employeeList);
}
?>

</select>

dainstructor

4:20 pm on Jan 2, 2007 (gmt 0)

10+ Year Member



I also believe that $row_employeeList['EmpNo'] is where the problem lies, however I'm not sure how to replace it with a variable that reflects the value (employee id number) of the selected employee in the drop down menu.

eelixduppy

4:27 pm on Jan 2, 2007 (gmt 0)



Well, firstly you can simplify this to something like the following:

<select name="employeeName" id="employeeName">
<?php
while ($row_employeeList = mysql_fetch_assoc($employeeList)) {
echo '<option value="'.$row_employeeList['EmpNo'].'" ';
echo (!strcmp($row_employeeList['EmpNo'], $row_employeeList['name']))? "selected >":">";
echo $row_employeeList['name'].'</option>';
}
?>
</select>
[b]<input type="submit" value="Get Information!" />[/b]

Now, unless you are using AJAX, this form must be submitted to the server before you can extract the data from the database.

Then on the action page, your query would then look something like this:


$query_getAssignment = "SELECT empNo, projectID, period1, period2, period3, period4, period5, period6, period7, period8, period9, period10, period11, period12, projects.projectName FROM assignments LEFT JOIN projects USING (projectID) WHERE assignments.empNo = '".[b]mysql_real_escape_string($_POST['employeeName'])[/b]."' ORDER BY assignments.projectID";

dainstructor

7:02 pm on Jan 2, 2007 (gmt 0)

10+ Year Member



Thanks eelixduppy. Problem solved.

Cheers!