无法弄清楚如何制作这种形式

时间:2014-02-14 00:14:00

标签: php mysql forms

我正在尝试使用PHP和MySQL建立一个调度系统。我有它所以我可以查看/编辑/删除员工,设备和客户。我需要做的最后一件事是制定时间表。我有以下表格

-- Lookup table for employee positions.
CREATE TABLE `EmployeePosition` (
    `EmployeePositionID` INTEGER AUTO_INCREMENT NOT NULL,
`Name` VARCHAR(100) NOT NULL,
CONSTRAINT `PK_Position` PRIMARY KEY (`EmployeePositionID`),
CONSTRAINT `UK_Position_Name` UNIQUE (`Name`)
);

-- Lookup table for eqipment types.
CREATE TABLE `EquipmentType` (
`EquipmentTypeID` INTEGER AUTO_INCREMENT NOT NULL,
`Name` VARCHAR(100) NOT NULL,
CONSTRAINT `PK_EquipmentType` PRIMARY KEY (`EquipmentTypeID`),
CONSTRAINT `UK_EquipmentType_Name` UNIQUE (`Name`)
);

-- Employee information.
CREATE TABLE `Employee` (
`EmployeeID` INTEGER AUTO_INCREMENT NOT NULL,
`Email` VARCHAR(100) NOT NULL,
`FirstName` VARCHAR(100) NOT NULL,
`LastName` VARCHAR(100) NOT NULL,
`EmployeePositionID` INTEGER NOT NULL,
`HomePhone` VARCHAR(32),
`CellPhone` VARCHAR(32),
`AccessLevel` TINYINT NOT NULL DEFAULT 0,
`IsDisabled` TINYINT NOT NULL DEFAULT 0,
`PwdHash` CHAR(40) NOT NULL DEFAULT 'X',
CONSTRAINT `PK_Employee` PRIMARY KEY (`EmployeeID`),
CONSTRAINT `FK_Employee_EmployeePositionID` FOREIGN KEY (`EmployeePositionID`)     REFERENCES `EmployeePosition` (`EmployeePositionID`),
CONSTRAINT `UK_Employee_Email` UNIQUE (`Email`)
);

-- Customer information.
CREATE TABLE `Customer` (
`CustomerID` INTEGER AUTO_INCREMENT NOT NULL,
`Name` VARCHAR(100) NOT NULL,
`Address1` VARCHAR(100),
`Address2` VARCHAR(100),
`City` VARCHAR(100),
`State` VARCHAR(2),
`ZipCode` VARCHAR(20),
`Phone` VARCHAR(32),
`Fax` VARCHAR(32),
`IsDisabled` TINYINT NOT NULL DEFAULT 0,
CONSTRAINT `PK_Customer` PRIMARY KEY (`CustomerID`),
CONSTRAINT `UK_Customer_Name` UNIQUE (`Name`)
);

-- Equipment information.
CREATE TABLE `Equipment` (
`EquipmentID` INTEGER AUTO_INCREMENT NOT NULL,
`Number` VARCHAR(32) NOT NULL,
`EquipmentTypeID` INTEGER NOT NULL,
`IsDisabled` TINYINT NOT NULL DEFAULT 0,
CONSTRAINT `PK_Equipment` PRIMARY KEY (`EquipmentID`),
CONSTRAINT `FK_Equipment_EquipmentTypeID` FOREIGN KEY (`EquipmentTypeID`) REFERENCES   `EquipmentType` (`EquipmentTypeID`),
CONSTRAINT `UK_Equipment_Number` UNIQUE (`Number`)
);

-- Basic job information.
CREATE TABLE `ScheduledJob` (
`ScheduledJobId` INTEGER AUTO_INCREMENT NOT NULL,
`CustomerID` INTEGER NOT NULL,
`JobDate` DATETIME NOT NULL,
`ReportTime` DATETIME NOT NULL,
`StartTime` DATETIME NOT NULL,
`JobDescription` MEDIUMTEXT NOT NULL,
CONSTRAINT `PK_ScheduledJob` PRIMARY KEY (`ScheduledJobId`),
CONSTRAINT `FK_ScheduledJob_CustomerID` FOREIGN KEY (`CustomerID`) REFERENCES  `Customer` (`CustomerID`)
);

-- Employees tied to jobs.
CREATE TABLE `ScheduledEmployee` (
`ScheduledEmployeeID` INTEGER AUTO_INCREMENT NOT NULL,
`ScheduledJobID` INTEGER NOT NULL,
`EmployeeID` INTEGER NOT NULL,
`Notes` MEDIUMTEXT,
CONSTRAINT `PK_ScheduledEmployee` PRIMARY KEY (`ScheduledEmployeeID`),
CONSTRAINT `FK_ScheduledEmployee_ScheduledJobID` FOREIGN KEY (`ScheduledJobID`) REFERENCES `ScheduledJob` (`ScheduledJobID`),
CONSTRAINT `FK_ScheduledEmployee_EmployeeID` FOREIGN KEY (`EmployeeID`) REFERENCES `Employee` (`EmployeeID`),
CONSTRAINT `UK_ScheduledEmployee` UNIQUE (`ScheduledJobID`, `EmployeeID`)
);

-- Equipment tied to jobs.
CREATE TABLE `ScheduledEquipment` (
`ScheduledEquipmentID` INTEGER AUTO_INCREMENT NOT NULL,
`ScheduledJobID` INTEGER NOT NULL,
`EquipmentID` INTEGER NOT NULL,
`Notes` MEDIUMTEXT,
CONSTRAINT `PK_ScheduledEquipment` PRIMARY KEY (`ScheduledEquipmentID`),
CONSTRAINT `FK_ScheduledEquipment_ScheduledJobID` FOREIGN KEY (`ScheduledJobID`) REFERENCES `ScheduledJob` (`ScheduledJobID`),
CONSTRAINT `FK_ScheduledEquipment_EquipmentID` FOREIGN KEY (`EquipmentID`) REFERENCES `Equipment` (`EquipmentID`),
CONSTRAINT `UK_ScheduledEquipment` UNIQUE (`ScheduledJobID`, `EquipmentID`)
);

我想要制作的表格应该是这样的:

+-------------------------------------------------------------------------------------------------
ScheduledJobID  JobDate  ReportTime  StartTime  CustomerID EmployeeID  EquipmentID  JobDescription
+-------------------------------------------------------------------------------------------------

CustomerID,EmployeeID,EquipmentID都应该是下拉框,我可以从已经存在的信息中选择 数据库。我不知道从哪里开始...请有人帮助我。我知道如何制作下拉菜单,因为我已经使用过它们 在我的添加表格中。

基本上我想要显示工作日期,向办公室报告的时间,向客户报告的时间(StartTime),我们正在为之工作的客户, 工作中的员工,工作中的设备和工作描述....我们是一家服务公司,这就是我们安排的方式。我们目前 在纸上做,我试图让我们进入21世纪。

1 个答案:

答案 0 :(得分:0)

类似的东西:

<?php
// assuming mysqli
$db = new mysqli(...);

// initialize variables
$employees = array();
$equipment = array();

$r = $db->query("SELECT `EmployeeID`, `FirstName` FROM `Employee`");
while($employee = $r->fetch_object()){ 
    $employees[$employee->EmployeeID] = $employee->FirstName;
}
// same for equipment

echo '<table>';
echo '<tr>';
echo '<th>ScheduledJobID</th><th>JobDate</th><th>ReportTime</th><th>StartTime</th><th>CustomerID</th><th>EmployeeID</th><th>EquipmentID</th><th>JobDescription</th>';
echo '</tr>';

// get your jobs
$result = $db->query("SELECT `ScheduledJob`.`ScheduledJobID`, `ScheduledJob`.`JobDate`, `ScheduledJob`.`ReportTime`, `ScheduledJob`.`StartTime`, `ScheduledJob`.`CustomerID`, `ScheduledEmployee`.`EmployeeID`,`ScheduledEquipment`.`EquipmentID`, `ScheduledJob`.`JobDescription` FROM `ScheduledJob` LEFT JOIN `ScheduledEmployee` ON (`ScheduledEmployee`.`ScheduledJobID`=`ScheduledJob`.`ScheduledJobId`) LEFT JOIN `ScheduledEquipment` ON (`ScheduledEquipment`.`ScheduledJobID`=`ScheduledJob`.`ScheduledJobId`)");
while($job = $result->fetch_object()){ 
    echo '<tr>';
    echo '<td>',$job->ScheduledJobID,'</td>';
    echo '<td>',$job->JobDate,'</td>';
    echo '<td>',$job->ReportTime,'</td>';
    echo '<td>',$job->StartTime,'</td>';
    echo '<td><select name="employee_in_job[',$job->ScheduledJobID,']">';
    foreach($employees as $id=>$name) { 
        if($id == $job->EmployeeID) {
            // selected emplyee according to your joblist
            echo '<option value="',$id,'" selected="selected">', $name, '</option>';
        } else {
            echo '<option value="',$id,'">', $name, '</option>';
        }
    }
    echo '</select></td>';
    echo '<td>',$job->EquipmentID,'</td>'; // same thing for equipment, but you can do that yourself
    echo '<td>',$job->JobDescription,'</td>';
    echo '</tr>';
}
echo '</table>';