我有一个基于 SQL 查询生成 HTML 表的函数。如何将整个表格存储在格式化的字符串中?这是表格的代码。正如这个论坛上的一个人之前建议的那样,我想将此字符串作为电子邮件的正文发送。我想我对如何做到这一点有一个好主意,所以对格式化字符串的帮助会很棒!
function tableGen($x) {
$term=$x;
$sql = mysql_query("select * from student_info where ID like '$term'");
echo "<h1>STUDENT DATA for ID: $term</h1>";
echo "<table>";
echo "<tr>
<th>ID</th>
<th>Project</th>
<th>Starter Project</th>
<th>Course</th>
<th>KDs Completed in your Course</th>
<th>Projects Completed</th>
<th>Project 1</th>
<th>P1KD1</th>
<th>P1KD2</th>
<th>P1KD3</th>
<th>P1KD4</th>
<th>P1KD5</th>
<th>Project 2</th>
<th>P2KD1</th>
<th>P2KD2</th>
<th>P2KD3</th>
<th>P2KD4</th>
<th>P2KD5</th>
<th>Project 3</th>
<th>P3KD1</th>
<th>P3KD2</th>
<th>P3KD3</th>
<th>P3KD4</th>
<th>P3KD5</th>
<th>Project 4</th>
<th>P4KD1</th>
<th>P4KD2</th>
<th>P4KD3</th>
<th>P4KD4</th>
<th>P4KD5</th>
</tr>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr><td>";
echo $row['ID'];
echo "</td><td>";
echo $row['Project'];
echo "</td><td>";
echo $row['Starter Project'];
echo "</td><td>";
echo $row['Course'];
echo "</td><td>";
echo $row['KDs completed in your course'];
echo "</td><td>";
echo $row['Projects Completed'];
echo "</td><td>";
echo $row['Project 1'];
echo "</td><td>";
echo $row['P 1 KD 1'];
echo "</td><td>";
echo $row['P 1 KD 2'];
echo "</td><td>";
echo $row['P 1 KD 3'];
echo "</td><td>";
echo $row['P 1 KD 4'];
echo "</td><td>";
echo $row['P 1 KD 5'];
echo "</td><td>";
echo $row['Project 2'];
echo "</td><td>";
echo $row['P 2 KD 1'];
echo "</td><td>";
echo $row['P 2 KD 2'];
echo "</td><td>";
echo $row['P 2 KD 3'];
echo "</td><td>";
echo $row['P 2 KD 4'];
echo "</td><td>";
echo $row['P 2 KD 5'];
echo "</td><td>";
echo $row['Project 3'];
echo "</td><td>";
echo $row['P 3 KD 1'];
echo "</td><td>";
echo $row['P 3 KD 2'];
echo "</td><td>";
echo $row['P 3 KD 3'];
echo "</td><td>";
echo $row['P 3 KD 4'];
echo "</td><td>";
echo $row['P 3 KD 5'];
echo "</td><td>";
echo $row['Project 4'];
echo "</td><td>";
echo $row['P 4 KD 1'];
echo "</td><td>";
echo $row['P 4 KD 2'];
echo "</td><td>";
echo $row['P 4 KD 3'];
echo "</td><td>";
echo $row['P 4 KD 4'];
echo "</td><td>";
echo $row['P 4 KD 5'];
echo "</td></tr>";
}
echo "</table>";
}