开发者

Need help displaying a dynamic table

I am designing a job rota planner for a company and need help displaying a dynamic table containing the staff details. I have the following tables in MySQL database: Staff, Event, and Job. The staff table holds staff details (staffed, name, address...etc), the Event table (eventide, eventName, Fromdate, Todate...etc) and the Job table holds (Jobid, Jobdate, Eventid(fk), Staffid (fk)). I need to dynamically display the available staff list from the staff table when the user selects the EVENT and the DATE (3 drop downs: date, month, and year) from a PHP form. I need t开发者_JS百科o display staff members that have not been assigned work on the selected date by checking the Jobdate in the Job table. I have been at this for all day and can't get around it. I am still learning PHP and would surely appreciate any help I can get. My current code displays all staff members when an event is selected:

 if(isset($_POST['submit'])) 
 { 
$eventId = $_POST['eventradio'];

 }
 $timePeriod = $_POST['timeperiod'];
 $Day = $_POST['day'];
 $Month = $_POST['month'];      
 $Year = $_POST['year'];
 $dateValue = $Year."-".$Month."-".$Day;
 $selectedDate = date("Y-m-d", strtotime($dateValue));

//construct the available staff list
if ($selectedDate)
    {
        $staffsql = "SELECT s.StaffId, s.LastName, s.FirstName
        FROM Staff s 
        WHERE s.StaffId NOT IN
        (SELECT J.StaffId
        FROM Job J
        WHERE J.JobDate = ".$selectedDate.")";
        $staffResult = mysql_query($staffsql) or die (mysql_error());

    }
if ($staffResult){
    echo "<p><table cellspacing='1' cellpadding='3'>";
    echo "<th colspan=6>List of Available Staff</th>";
    echo "</tr><tr><th> Select</th><th>Id</th><th></th><th>Last Name
        </th><th></th><th>First Name </th></tr>";

    while ($staffarray = mysql_fetch_array($staffResult))
    {
        echo "<tr onMouseOver= this.bgColor = 'red' onMouseOut =this.bgColor = 'white' bgcolor= 
            '#FFFFFF'> <td align=center><input type='checkbox' name='selectbox[]'
            id='selectbox[]' value=".$staffarray['StaffId'].">
            </td><td align=left>".$staffarray['StaffId']."
            </td><td>&nbsp&nbsp</td><td align=center>".$staffarray['LastName']."
            </td><td>&nbsp&nbsp</td><td align=center>".$staffarray['FirstName']."
            </td></tr>";
    }
        echo "</table>";
    }
    else {
        echo "<br> The Staff list can not be displayed!";
    }       
    echo "</td></tr>";
    echo "<tr><td></td>";
    echo "<td align=center><input type='submit' name='Submit' value='Assign Staff'>&nbsp&nbsp";
    echo "<input type='reset' value='Start Over'>";
    echo "</td></tr>";
    echo "</table>";


You need to do 1 of 2 things.

a.) add an onchange event to your select list and make an AJAX call to your server to pull back the table data, or

b.) add an onchange event to your select list and submit the form/page to itself (thus including the value selected from the select list

In your PHP (either way) using the parameter on the request (if it exists) load the applicable data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜