-1

我有三张桌子:

员工(EmployeeID,Fname,Lname...)
ProjectHeader(ProjectID,LeadID,Status....)
ProjectDetails(ProjectDetailsID,ProjectID....)

这是我当前的代码:

$get_projects = "SELECT DISTINCT projectheader.ProjectID, projectheader.ProjectName ,projectheader.Lead, projectheader.StartDate, projectheader.EndDate, projectheader.Status, projectheader.Remarks, CONCAT (employee.Firstname, ' ' ,employee.Lastname) AS EmployeeName
FROM employee, projectheader, projectdetails
WHERE projectheader.ProjectID = projectdetails.ProjectID
AND projectheader.Lead = employee.EmployeeID";

$result = mysql_query($get_projects);

$project_id = "";
$project_name = "";
$project_lead = "";
$project_start = "";
$project_end = "";
$project_status = "";
$project_remarks = "";
$table = "";
$table .= "<table border='1'> <th>ProjectID</th>" 
."<th>Project name</th>" 
."<th>Lead</th>" 
."<th>Start</th>" 
."<th>End</th>" 
."<th>Status</th>" 
."<th>Remark</th>";
while($row = mysql_fetch_array($result))
{
    $project_id = $row['ProjectID'];
    $project_name =  $row['ProjectName'];
    $project_lead = $row['EmployeeName'];
    $project_start = $row['StartDate'];
    $project_end = $row['EndDate'];
    $project_status = $row['Status'];
    $project_remarks = $row['Remarks'];

    $table .= "<tr>";
    $table .= "<td>" .$project_id ."</td>"; 
    $table .= "<td>" .$project_name ."</td>"; 
    $table .= "<td>" .$project_lead ."</td>"; 
    $table .= "<td>" .$project_start ."</td>"; 
    $table .= "<td>" .$project_end ."</td>"; 
    $table .= "<td>" .$project_status ."</td>"; 
    $table .= "<td>" .$project_remarks ."</td>"; 
    $table .= "</tr>";

}
$table .= "</table>";
echo $table;
?>

我现在拥有的是这样的在此处输入图像描述

我想要的不是将每一行都显示在一个表中,而是每一行都在表中。

在此处输入图像描述

4

1 回答 1

2

只需tablewhile循环内创建一个新表,它将为每个 SQL 结果行创建一个新表。请注意,您还缺少tr表头周围的标签 ( th)

while($row = mysql_fetch_array($result))
{
    $table .= "<table border='1'>"
    ."<tr><th>ProjectID</th>" 
    ."<th>Project name</th>" 
    ."<th>Lead</th>" 
    ."<th>Start</th>" 
    ."<th>End</th>" 
    ."<th>Status</th>" 
    ."<th>Remark</th></tr>";

...

    $table .= "<tr>";
    $table .= "<td>" .$project_id ."</td>"; 
    $table .= "<td>" .$project_name ."</td>"; 
    $table .= "<td>" .$project_lead ."</td>"; 
    $table .= "<td>" .$project_start ."</td>"; 
    $table .= "<td>" .$project_end ."</td>"; 
    $table .= "<td>" .$project_status ."</td>"; 
    $table .= "<td>" .$project_remarks ."</td>"; 
    $table .= "</tr>";
    $table .= "</table>";
}

echo $table;
于 2012-06-23T13:16:43.857 回答