我有这个PHP,可以输出经理列表,并在其下方列出其员工和要求。
这现在很好用- 但是 ,我想将所有HTML存储在每个管理器的变量中,而不是在页面上输出。我该如何实现?
<?php
while($row = $resultt->fetch_assoc()) {
$arr = explode("@", $row['email'], 2);
$first = $arr[0];
$first = str_replace('.','-',$first);
$email = $row['email'];
$sql2 = "SELECT * FROM user WHERE manager_email LIKE '%".$email."%'";
$resultt2 = $con->query($sql2);
echo '<table class="'.$first.'">';
$i++;
while($row2 = $resultt2->fetch_assoc()) {
echo '<tr><td>'.$row2['email'].':</td>';
$sql3 = "SELECT * FROM requests WHERE submitted_by = '".$row2['email']."'";
$resultt3 = $con->query($sql3);
$count = 0;
while($row3 = $resultt3->fetch_assoc()) {
$count++;
}
echo '<td>'.$count.'</td></tr>';
}
echo '</table>';
}
谢谢您的指导。
答案 0 :(得分:1)
$output = '';
while($row = $resultt->fetch_assoc()) {
$arr = explode("@", $row['email'], 2);
$first = $arr[0];
$first = str_replace('.','-',$first);
$email = $row['email'];
$sql2 = "SELECT * FROM user WHERE manager_email LIKE '%".$email."%'";
$resultt2 = $con->query($sql2);
$output .= '<table class="'.$first.'">';
$i++;
while($row2 = $resultt2->fetch_assoc()) {
$output .= '<tr><td>'.$row2['email'].':</td>';
$sql3 = "SELECT * FROM requests WHERE submitted_by = '".$row2['email']."'";
$resultt3 = $con->query($sql3);
$count = 0;
while($row3 = $resultt3->fetch_assoc()) {
$count++;
}
$output .= '<td>'.$count.'</td></tr>';
}
$output .= '</table>';
}
echo $output;
所有输出现在存储在 $ output
中